mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix clippy warnings
This commit is contained in:
parent
bd78bca91b
commit
6ce2dba8a1
@ -75,15 +75,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn find_closest_pair(pair: &ColorPair, max_colors: i16) -> (i16, i16) {
|
||||
fn find_closest_pair(pair: ColorPair, max_colors: i16) -> (i16, i16) {
|
||||
(
|
||||
find_closest(&pair.front, max_colors),
|
||||
find_closest(&pair.back, max_colors),
|
||||
find_closest(pair.front, max_colors),
|
||||
find_closest(pair.back, max_colors),
|
||||
)
|
||||
}
|
||||
|
||||
fn find_closest(color: &Color, max_colors: i16) -> i16 {
|
||||
match *color {
|
||||
fn find_closest(color: Color, max_colors: i16) -> i16 {
|
||||
match color {
|
||||
Color::TerminalDefault => -1,
|
||||
Color::Dark(BaseColor::Black) => 0,
|
||||
Color::Dark(BaseColor::Red) => 1,
|
||||
|
@ -153,7 +153,7 @@ impl InputParser {
|
||||
}
|
||||
}
|
||||
|
||||
fn find_closest_pair(pair: &ColorPair) -> (i16, i16) {
|
||||
fn find_closest_pair(pair: ColorPair) -> (i16, i16) {
|
||||
super::find_closest_pair(pair, ncurses::COLORS() as i16)
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ impl Backend {
|
||||
let mut pairs = self.pairs.borrow_mut();
|
||||
|
||||
// Find if we have this color in stock
|
||||
let (front, back) = find_closest_pair(&pair);
|
||||
let (front, back) = find_closest_pair(pair);
|
||||
if pairs.contains_key(&(front, back)) {
|
||||
// We got it!
|
||||
pairs[&(front, back)]
|
||||
|
@ -272,7 +272,7 @@ impl InputParser {
|
||||
}
|
||||
}
|
||||
|
||||
fn find_closest_pair(pair: &ColorPair) -> (i16, i16) {
|
||||
fn find_closest_pair(pair: ColorPair) -> (i16, i16) {
|
||||
super::find_closest_pair(pair, pancurses::COLORS() as i16)
|
||||
}
|
||||
|
||||
@ -334,7 +334,7 @@ impl Backend {
|
||||
/// Checks the pair in the cache, or re-define a color if needed.
|
||||
fn get_or_create(&self, pair: ColorPair) -> i32 {
|
||||
let mut pairs = self.pairs.borrow_mut();
|
||||
let pair = find_closest_pair(&pair);
|
||||
let pair = find_closest_pair(pair);
|
||||
|
||||
// Find if we have this color in stock
|
||||
if pairs.contains_key(&pair) {
|
||||
|
@ -37,13 +37,13 @@ impl Orientation {
|
||||
///
|
||||
/// (`Horizontal` will return the x value,
|
||||
/// and `Vertical` will return the y value.)
|
||||
pub fn get<T: Clone>(&self, v: &XY<T>) -> T {
|
||||
v.get(*self).clone()
|
||||
pub fn get<T: Clone>(self, v: &XY<T>) -> T {
|
||||
v.get(self).clone()
|
||||
}
|
||||
|
||||
/// Returns the other orientation.
|
||||
pub fn swap(&self) -> Self {
|
||||
match *self {
|
||||
pub fn swap(self) -> Self {
|
||||
match self {
|
||||
Orientation::Horizontal => Orientation::Vertical,
|
||||
Orientation::Vertical => Orientation::Horizontal,
|
||||
}
|
||||
@ -51,8 +51,8 @@ impl Orientation {
|
||||
|
||||
/// Returns a mutable reference to the component of the given vector
|
||||
/// corresponding to this orientation.
|
||||
pub fn get_ref<'a, 'b, T>(&'a self, v: &'b mut XY<T>) -> &'b mut T {
|
||||
match *self {
|
||||
pub fn get_ref<T>(self, v: &mut XY<T>) -> &mut T {
|
||||
match self {
|
||||
Orientation::Horizontal => &mut v.x,
|
||||
Orientation::Vertical => &mut v.y,
|
||||
}
|
||||
@ -63,8 +63,8 @@ impl Orientation {
|
||||
///
|
||||
/// For an horizontal view, returns (Sum(x), Max(y)).
|
||||
/// For a vertical view, returns (Max(x),Sum(y)).
|
||||
pub fn stack<'a, T: Iterator<Item = &'a Vec2>>(&self, iter: T) -> Vec2 {
|
||||
match *self {
|
||||
pub fn stack<'a, T: Iterator<Item = &'a Vec2>>(self, iter: T) -> Vec2 {
|
||||
match self {
|
||||
Orientation::Horizontal => {
|
||||
iter.fold(Vec2::zero(), |a, b| a.stack_horizontal(b))
|
||||
}
|
||||
@ -75,7 +75,7 @@ impl Orientation {
|
||||
}
|
||||
|
||||
/// Creates a new `Vec2` with `value` in `self`'s axis.
|
||||
pub fn make_vec(&self, main_axis: usize, second_axis: usize) -> Vec2 {
|
||||
pub fn make_vec(self, main_axis: usize, second_axis: usize) -> Vec2 {
|
||||
let mut result = Vec2::zero();
|
||||
*self.get_ref(&mut result) = main_axis;
|
||||
*self.swap().get_ref(&mut result) = second_axis;
|
||||
|
@ -260,8 +260,8 @@ impl MouseEvent {
|
||||
/// Returns the button used by this event, if any.
|
||||
///
|
||||
/// Returns `None` if `self` is `WheelUp` or `WheelDown`.
|
||||
pub fn button(&self) -> Option<MouseButton> {
|
||||
match *self {
|
||||
pub fn button(self) -> Option<MouseButton> {
|
||||
match self {
|
||||
MouseEvent::Press(btn)
|
||||
| MouseEvent::Release(btn)
|
||||
| MouseEvent::Hold(btn) => Some(btn),
|
||||
|
@ -308,7 +308,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
offset: self.offset,
|
||||
size: self.size,
|
||||
focused: self.focused,
|
||||
theme: theme,
|
||||
theme,
|
||||
backend: self.backend,
|
||||
output_size: self.output_size,
|
||||
content_offset: self.content_offset,
|
||||
|
@ -14,7 +14,7 @@ impl ColorPair {
|
||||
/// Return an inverted color pair.
|
||||
///
|
||||
/// With swapped front abd back color.
|
||||
pub fn invert(&self) -> Self {
|
||||
pub fn invert(self) -> Self {
|
||||
ColorPair {
|
||||
front: self.back,
|
||||
back: self.front,
|
||||
|
@ -67,7 +67,7 @@ impl Palette {
|
||||
/// Returns `None` if the given key was not found.
|
||||
pub fn custom<'a>(&'a self, key: &str) -> Option<&'a Color> {
|
||||
self.custom.get(key).and_then(|node| {
|
||||
if let &PaletteNode::Color(ref color) = node {
|
||||
if let PaletteNode::Color(ref color) = *node {
|
||||
Some(color)
|
||||
} else {
|
||||
None
|
||||
|
@ -270,9 +270,7 @@ impl Dialog {
|
||||
}
|
||||
|
||||
/// Returns an iterator on this buttons for this dialog.
|
||||
pub fn buttons_mut<'a>(
|
||||
&'a mut self,
|
||||
) -> impl Iterator<Item = &'a mut Button> {
|
||||
pub fn buttons_mut(&mut self) -> impl Iterator<Item = &mut Button> {
|
||||
self.buttons.iter_mut().map(|b| &mut b.button.view)
|
||||
}
|
||||
|
||||
|
@ -585,10 +585,12 @@ impl View for EditView {
|
||||
let selected = self.content[self.cursor..]
|
||||
.graphemes(true)
|
||||
.next()
|
||||
.expect(&format!(
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Found no char at cursor {} in {}",
|
||||
self.cursor, &self.content
|
||||
));
|
||||
)
|
||||
});
|
||||
if self.secret {
|
||||
make_small_stars(selected.width())
|
||||
} else {
|
||||
|
@ -245,11 +245,12 @@ where
|
||||
let offsets = self.scrollbar_thumb_offsets(lengths);
|
||||
|
||||
// Iterate on axises, and keep the one we grabbed.
|
||||
for (orientation, pos, length, offset) in
|
||||
if let Some((orientation, pos, length, offset)) =
|
||||
XY::zip4(Orientation::pair(), position, lengths, offsets)
|
||||
.keep(grabbed.and(self.enabled))
|
||||
.into_iter()
|
||||
.filter_map(|x| x)
|
||||
.next()
|
||||
{
|
||||
if pos >= offset && pos < offset + length {
|
||||
// We grabbed the thumb! Now scroll from that position.
|
||||
|
26
src/xy.rs
26
src/xy.rs
@ -10,6 +10,15 @@ pub struct XY<T> {
|
||||
pub y: T,
|
||||
}
|
||||
|
||||
impl<T> IntoIterator for XY<T> {
|
||||
type Item = T;
|
||||
type IntoIter = iter::Chain<iter::Once<T>, iter::Once<T>>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
iter::once(self.x).chain(iter::once(self.y))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> XY<T> {
|
||||
/// Creates a new `XY` from the given values.
|
||||
pub fn new(x: T, y: T) -> Self {
|
||||
@ -88,11 +97,6 @@ impl<T> XY<T> {
|
||||
iter::once(&self.x).chain(iter::once(&self.y))
|
||||
}
|
||||
|
||||
/// Creates an iterator that returns `x`, then `y`.
|
||||
pub fn into_iter(self) -> iter::Chain<iter::Once<T>, iter::Once<T>> {
|
||||
iter::once(self.x).chain(iter::once(self.y))
|
||||
}
|
||||
|
||||
/// Returns a reference to the value on the given axis.
|
||||
pub fn get(&self, o: Orientation) -> &T {
|
||||
match o {
|
||||
@ -177,34 +181,34 @@ impl<T> XY<Option<T>> {
|
||||
|
||||
impl XY<bool> {
|
||||
/// Returns `true` if any of `x` or `y` is `true`.
|
||||
pub fn any(&self) -> bool {
|
||||
pub fn any(self) -> bool {
|
||||
use std::ops::BitOr;
|
||||
self.fold(BitOr::bitor)
|
||||
}
|
||||
|
||||
/// Returns `true` if both `x` and `y` are `true`.
|
||||
pub fn both(&self) -> bool {
|
||||
pub fn both(self) -> bool {
|
||||
use std::ops::BitAnd;
|
||||
self.fold(BitAnd::bitand)
|
||||
}
|
||||
|
||||
/// For each axis, keeps elements from `other` if `self` is `true`.
|
||||
pub fn select<T>(&self, other: XY<T>) -> XY<Option<T>> {
|
||||
pub fn select<T>(self, other: XY<T>) -> XY<Option<T>> {
|
||||
self.zip_map(other, |keep, o| if keep { Some(o) } else { None })
|
||||
}
|
||||
|
||||
/// For each axis, selects `if_true` if `self` is true, else `if_false`.
|
||||
pub fn select_or<T>(&self, if_true: XY<T>, if_false: XY<T>) -> XY<T> {
|
||||
pub fn select_or<T>(self, if_true: XY<T>, if_false: XY<T>) -> XY<T> {
|
||||
self.select(if_true).unwrap_or(if_false)
|
||||
}
|
||||
|
||||
/// Returns a term-by-term AND operation.
|
||||
pub fn and(&self, other: Self) -> Self {
|
||||
pub fn and(self, other: Self) -> Self {
|
||||
self.zip_map(other, |s, o| s && o)
|
||||
}
|
||||
|
||||
/// Returns a term-by-term OR operation.
|
||||
pub fn or(&self, other: Self) -> Self {
|
||||
pub fn or(self, other: Self) -> Self {
|
||||
self.zip_map(other, |s, o| s || o)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user