Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
gyscos committed Jan 9, 2025
1 parent d10f1cc commit b50edc9
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 51 deletions.
2 changes: 1 addition & 1 deletion cursive-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ readme = "README.md"
repository = "https://github.com/gyscos/cursive"
version = "0.4.6"
edition = "2021"
rust-version = "1.61"
rust-version = "1.70"
include = ["src/**/*", "LICENSE", "README.md"]

[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion cursive-core/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub struct Window<'a> {
viewport: Rect,
}

impl<'a> Window<'a> {
impl Window<'_> {
/// Returns the cell at the given location.
///
/// Returns `None` if the cell is empty because the previous one was double-wide.
Expand Down
5 changes: 4 additions & 1 deletion cursive-core/src/builder/resolvable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,10 @@ impl Resolvable for crate::view::Offset {
match key.as_str() {
"Absolute" | "absolute" => Ok(Self::Absolute(context.resolve(value)?)),
"Parent" | "parent" => Ok(Self::Parent(context.resolve(value)?)),
_ => Err(Error::invalid_config("Unexpected key `{key}`.", config)),
_ => Err(Error::invalid_config(
format!("Unexpected key `{key}`."),
config,
)),
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions cursive-core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ impl EventTrigger {
/// );
/// ```
pub fn has_tag<T: PartialEq + 'static>(&self, tag: &T) -> bool {
(*self.tag)
.as_any()
.downcast_ref::<T>()
.map_or(false, |t| tag == t)
(*self.tag).as_any().downcast_ref::<T>() == Some(tag)
}

/// Checks if this trigger applies to the given `Event`.
Expand Down
1 change: 0 additions & 1 deletion cursive-core/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use std::sync::{Mutex, RwLock};
/// logger::set_external_filter_level(LevelFilter::Debug);
/// logger::init();
/// ```
pub struct CursiveLogger;

lazy_static! {
Expand Down
4 changes: 2 additions & 2 deletions cursive-core/src/utils/lines/simple/lines_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<'a> DummySpannedText<'a> {
}
}

impl<'a> SpannedText for DummySpannedText<'a> {
impl SpannedText for DummySpannedText<'_> {
type S = IndexedSpan<()>;

fn source(&self) -> &str {
Expand Down Expand Up @@ -58,7 +58,7 @@ impl<'a> LinesIterator<'a> {
}
}

impl<'a> Iterator for LinesIterator<'a> {
impl Iterator for LinesIterator<'_> {
type Item = Row;

fn next(&mut self) -> Option<Row> {
Expand Down
2 changes: 1 addition & 1 deletion cursive-core/src/utils/markup/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl<'a> Parser<'a> {
}
}

impl<'a> Iterator for Parser<'a> {
impl Iterator for Parser<'_> {
type Item = StyledIndexedSpan;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
7 changes: 2 additions & 5 deletions cursive-core/src/utils/markup/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,12 @@ fn heading(level: usize) -> &'static str {
&"##########"[..level]
}

impl<'a> Iterator for Parser<'a> {
impl Iterator for Parser<'_> {
type Item = StyledIndexedSpan;

fn next(&mut self) -> Option<Self::Item> {
loop {
let next = match self.parser.next() {
None => return None,
Some(event) => event,
};
let next = self.parser.next()?;

match next {
Event::Start(tag) => match tag {
Expand Down
2 changes: 1 addition & 1 deletion cursive-core/src/utils/markup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct PlainStr<'a> {
span: IndexedSpan<Style>,
}

impl<'a> SpannedText for PlainStr<'a> {
impl SpannedText for PlainStr<'_> {
type S = IndexedSpan<Style>;

fn source(&self) -> &str {
Expand Down
4 changes: 2 additions & 2 deletions cursive-core/src/utils/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<T> Default for SpannedString<T> {
}
}

impl<'a, T> SpannedText for &'a SpannedString<T> {
impl<T> SpannedText for &SpannedString<T> {
type S = IndexedSpan<T>;

fn source(&self) -> &str {
Expand Down Expand Up @@ -173,7 +173,7 @@ where
}
}

impl<'a, T> Clone for SpannedStr<'a, T> {
impl<T> Clone for SpannedStr<'_, T> {
fn clone(&self) -> Self {
SpannedStr {
source: self.source,
Expand Down
10 changes: 2 additions & 8 deletions cursive-core/src/views/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,7 @@ impl Dialog {

let overhead_bottom = self.padding.bottom + self.borders.bottom + 1;

let y = match printer.size.y.checked_sub(overhead_bottom) {
Some(y) => y,
None => return None,
};
let y = printer.size.y.checked_sub(overhead_bottom)?;

for (i, button) in self.buttons.iter().enumerate() {
let size = button.button.size;
Expand Down Expand Up @@ -712,10 +709,7 @@ impl Dialog {
return None;
}

let position = match position.checked_sub(offset) {
None => return None,
Some(pos) => pos,
};
let position = position.checked_sub(offset)?;

// eprintln!("Rel pos: {:?}", position);

Expand Down
7 changes: 2 additions & 5 deletions cursive-core/src/views/fixed_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl FixedLayout {
fn iter_mut<'a>(
source: Direction,
children: &'a mut [Child],
) -> Box<dyn Iterator<Item = (usize, &mut Child)> + 'a> {
) -> Box<dyn Iterator<Item = (usize, &'a mut Child)> + 'a> {
let children = children.iter_mut().enumerate();
match source {
Direction::Rel(Relative::Front) => Box::new(children),
Expand Down Expand Up @@ -240,10 +240,7 @@ impl FixedLayout {
return None;
}

let position = match position.checked_sub(offset) {
None => return None,
Some(pos) => pos,
};
let position = position.checked_sub(offset)?;

if let Some((i, res)) = self
.children
Expand Down
7 changes: 2 additions & 5 deletions cursive-core/src/views/linear_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl LinearLayout {
&'a mut self,
from_focus: bool,
source: direction::Relative,
) -> Box<dyn Iterator<Item = (usize, &mut Child)> + 'a> {
) -> Box<dyn Iterator<Item = (usize, &'a mut Child)> + 'a> {
match source {
direction::Relative::Front => {
let start = if from_focus { self.focus } else { 0 };
Expand Down Expand Up @@ -388,10 +388,7 @@ impl LinearLayout {
return None;
}

let position = match position.checked_sub(offset) {
None => return None,
Some(pos) => pos,
};
let position = position.checked_sub(offset)?;

// Find the selected child
// Let's only care about the coordinate for our orientation.
Expand Down
14 changes: 4 additions & 10 deletions cursive-core/src/views/list_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl ListView {
&'a mut self,
from_focus: bool,
source: direction::Relative,
) -> Box<dyn Iterator<Item = (usize, &mut ListChild)> + 'a> {
) -> Box<dyn Iterator<Item = (usize, &'a mut ListChild)> + 'a> {
match source {
direction::Relative::Front => {
let start = if from_focus { self.focus } else { 0 };
Expand Down Expand Up @@ -316,10 +316,7 @@ impl ListView {
return None;
}

let mut position = match position.checked_sub(offset) {
None => return None,
Some(pos) => pos,
};
let mut position = position.checked_sub(offset)?;

// eprintln!("Rel pos: {:?}", position);

Expand All @@ -339,11 +336,8 @@ impl ListView {

// We found the correct target, try to focus it.
if let ListChild::Row(_, ref mut view) = child {
match view.take_focus(direction::Direction::none()) {
Ok(res) => {
return Some(self.set_focus_unchecked(i).and(res));
}
Err(CannotFocus) => (),
if let Ok(res) = view.take_focus(direction::Direction::none()) {
return Some(self.set_focus_unchecked(i).and(res));
}
}
// We found the target, but we can't focus it.
Expand Down
2 changes: 1 addition & 1 deletion cursive-macros/src/builder/callback_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ This is mostly useful when using this view in a template."#
..
}) = predicate
{
type_ident.map_or(false, |ident| !path.path.is_ident(ident))
type_ident.is_some_and(|ident| !path.path.is_ident(ident))
} else {
false
}
Expand Down
6 changes: 3 additions & 3 deletions cursive/src/backends/puppet/observed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl ObservedPieceInterface for ObservedScreen {
}
}

impl<'a> ObservedPieceInterface for ObservedPiece<'a> {
impl ObservedPieceInterface for ObservedPiece<'_> {
fn min(&self) -> Vec2 {
self.min
}
Expand Down Expand Up @@ -365,7 +365,7 @@ impl<'a> ObservedLine<'a> {
}
}

impl<'a> ObservedPieceInterface for ObservedLine<'a> {
impl ObservedPieceInterface for ObservedLine<'_> {
fn min(&self) -> Vec2 {
self.line_start
}
Expand All @@ -379,7 +379,7 @@ impl<'a> ObservedPieceInterface for ObservedLine<'a> {
}
}

impl<'a> Display for ObservedLine<'a> {
impl Display for ObservedLine<'_> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{}", self.as_strings().remove(0))
}
Expand Down

0 comments on commit b50edc9

Please sign in to comment.