mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Fix clippy lints
This commit is contained in:
parent
994a3cf545
commit
47d8d23198
@ -63,6 +63,8 @@ pub type ScreenId = usize;
|
||||
/// [`send_wrapper`]: https://crates.io/crates/send_wrapper
|
||||
pub type CbSink = Sender<Box<dyn FnOnce(&mut Cursive) + Send>>;
|
||||
|
||||
new_default!(Cursive);
|
||||
|
||||
impl Cursive {
|
||||
/// Creates a new Cursive root, and initialize the back-end.
|
||||
///
|
||||
|
@ -85,7 +85,7 @@ 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 = Vec2>>(self, iter: T) -> Vec2 {
|
||||
pub fn stack<T: Iterator<Item = Vec2>>(self, iter: T) -> Vec2 {
|
||||
match self {
|
||||
Orientation::Horizontal => {
|
||||
iter.fold(Vec2::zero(), |a, b| a.stack_horizontal(&b))
|
||||
|
@ -101,12 +101,14 @@ impl EventTrigger {
|
||||
/// Only bare arrow keys without modifiers (Shift, Ctrl, Alt) will be accepted.
|
||||
pub fn arrows() -> Self {
|
||||
Self::from_fn_and_tag(
|
||||
|e| match e {
|
||||
Event::Key(Key::Left)
|
||||
| Event::Key(Key::Down)
|
||||
| Event::Key(Key::Up)
|
||||
| Event::Key(Key::Right) => true,
|
||||
_ => false,
|
||||
|e| {
|
||||
matches!(
|
||||
e,
|
||||
Event::Key(Key::Left)
|
||||
| Event::Key(Key::Down)
|
||||
| Event::Key(Key::Up)
|
||||
| Event::Key(Key::Right)
|
||||
)
|
||||
},
|
||||
"arrows",
|
||||
)
|
||||
@ -115,9 +117,9 @@ impl EventTrigger {
|
||||
/// Returns an `EventTrigger` that only accepts mouse events.
|
||||
pub fn mouse() -> Self {
|
||||
Self::from_fn_and_tag(
|
||||
|e| match e {
|
||||
Event::Mouse { .. } => true,
|
||||
_ => false,
|
||||
|e| {
|
||||
matches!(e,
|
||||
Event::Mouse { .. })
|
||||
},
|
||||
"mouse",
|
||||
)
|
||||
@ -256,18 +258,12 @@ impl EventResult {
|
||||
|
||||
/// Returns `true` if `self` is `EventResult::Consumed`.
|
||||
pub fn is_consumed(&self) -> bool {
|
||||
match *self {
|
||||
EventResult::Consumed(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*self, EventResult::Consumed(_))
|
||||
}
|
||||
|
||||
/// Returns `true` if `self` contains a callback.
|
||||
pub fn has_callback(&self) -> bool {
|
||||
match *self {
|
||||
EventResult::Consumed(Some(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*self, EventResult::Consumed(Some(_)))
|
||||
}
|
||||
|
||||
/// Process this result if it is a callback.
|
||||
@ -463,12 +459,10 @@ impl MouseEvent {
|
||||
/// It means you should be able to grab a scroll bar, and move the mouse
|
||||
/// away from the view, without actually changing the focus.
|
||||
pub fn grabs_focus(self) -> bool {
|
||||
match self {
|
||||
matches!(self,
|
||||
MouseEvent::Press(_)
|
||||
| MouseEvent::WheelUp
|
||||
| MouseEvent::WheelDown => true,
|
||||
_ => false,
|
||||
}
|
||||
| MouseEvent::WheelDown)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,26 +51,17 @@ impl MenuItem {
|
||||
|
||||
/// Returns `true` if `self` is a delimiter.
|
||||
pub fn is_delimiter(&self) -> bool {
|
||||
match *self {
|
||||
MenuItem::Delimiter => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*self, MenuItem::Delimiter)
|
||||
}
|
||||
|
||||
/// Returns `true` if `self` is a leaf node.
|
||||
pub fn is_leaf(&self) -> bool {
|
||||
match *self {
|
||||
MenuItem::Leaf(_, _) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*self, MenuItem::Leaf(_, _))
|
||||
}
|
||||
|
||||
/// Returns `true` if `self` is a subtree.
|
||||
pub fn is_subtree(&self) -> bool {
|
||||
match *self {
|
||||
MenuItem::Subtree(_, _) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*self, MenuItem::Subtree(_, _))
|
||||
}
|
||||
|
||||
/// Return a mutable reference to the subtree, if applicable.
|
||||
|
@ -183,10 +183,10 @@ impl Color {
|
||||
}
|
||||
|
||||
fn parse_special(value: &str) -> Option<Color> {
|
||||
if value.starts_with('#') {
|
||||
parse_hex(&value[1..])
|
||||
} else if value.starts_with("0x") {
|
||||
parse_hex(&value[2..])
|
||||
if let Some(value) = value.strip_prefix('#') {
|
||||
parse_hex(value)
|
||||
} else if let Some(value) = value.strip_prefix("0x") {
|
||||
parse_hex(value)
|
||||
} else if value.len() == 6 {
|
||||
parse_hex(value)
|
||||
} else if value.len() == 3 {
|
||||
|
@ -1,6 +1,7 @@
|
||||
use enumset::EnumSetType;
|
||||
|
||||
/// Text effect
|
||||
#[allow(clippy::derive_hash_xor_eq)] // We do derive it through EnumSetType
|
||||
#[derive(EnumSetType, Debug, Hash)]
|
||||
pub enum Effect {
|
||||
/// No effect
|
||||
|
@ -71,6 +71,7 @@ pub type OnSubmit = dyn Fn(&mut Cursive, &str);
|
||||
/// ```
|
||||
pub struct EditView {
|
||||
/// Current content.
|
||||
#[allow(clippy::rc_buffer)] // Rc::make_mut is what we want here.
|
||||
content: Rc<String>,
|
||||
|
||||
/// Cursor position in the content, in bytes.
|
||||
@ -357,6 +358,7 @@ impl EditView {
|
||||
}
|
||||
|
||||
/// Get the current text.
|
||||
#[allow(clippy::rc_buffer)]
|
||||
pub fn get_content(&self) -> Rc<String> {
|
||||
Rc::clone(&self.content)
|
||||
}
|
||||
|
@ -32,10 +32,7 @@ pub enum GraphemePart {
|
||||
impl GraphemePart {
|
||||
/// Returns true iff GraphemePart is Continuation
|
||||
pub fn is_continuation(&self) -> bool {
|
||||
match *self {
|
||||
GraphemePart::Continuation => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(*self, GraphemePart::Continuation)
|
||||
}
|
||||
|
||||
/// Returns Some(String) if GraphemePart is Begin(String), else None.
|
||||
|
@ -1,5 +1,9 @@
|
||||
use crate::{backend, backends, Cursive};
|
||||
|
||||
type Initializer =
|
||||
dyn FnMut()
|
||||
-> Result<Box<dyn backend::Backend>, Box<dyn std::error::Error>>;
|
||||
|
||||
/// A runnable wrapper around `Cursive`, bundling the backend initializer.
|
||||
///
|
||||
/// This struct embeds both `Cursive` and a backend-initializer
|
||||
@ -12,12 +16,7 @@ use crate::{backend, backends, Cursive};
|
||||
/// regular `Cursive` object.
|
||||
pub struct CursiveRunnable {
|
||||
siv: Cursive,
|
||||
backend_init: Box<
|
||||
dyn FnMut() -> Result<
|
||||
Box<dyn backend::Backend>,
|
||||
Box<dyn std::error::Error>,
|
||||
>,
|
||||
>,
|
||||
backend_init: Box<Initializer>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for CursiveRunnable {
|
||||
|
Loading…
Reference in New Issue
Block a user