diff --git a/kakplugin/src/errors.rs b/kakplugin/src/errors.rs index f716401..68d7e0b 100644 --- a/kakplugin/src/errors.rs +++ b/kakplugin/src/errors.rs @@ -43,7 +43,7 @@ impl ToString for KakError { Self::KakResponse(_) => "Invalid kak response", Self::Io(_) => "IO error", Self::NotImplemented(_) => "Not Implemented", - Self::Custom(s) => &s, + Self::Custom(s) => s, } ) } diff --git a/kakplugin/src/lib.rs b/kakplugin/src/lib.rs index 0b06343..df8f37a 100644 --- a/kakplugin/src/lib.rs +++ b/kakplugin/src/lib.rs @@ -59,9 +59,7 @@ pub fn get_selections_with_desc() -> Result, KakError> { } let min_selection = selections_desc.iter().min().ok_or_else(|| { - KakError::KakResponse(format!( - "Selections are empty, which should not be possible" - )) + KakError::KakResponse("Selections are empty, which should not be possible".to_string()) })?; // Kakoune prints selections in file order, but prints selections_desc rotated based on current selection diff --git a/src/set.rs b/src/set.rs index 5e2b04b..83b3b74 100644 --- a/src/set.rs +++ b/src/set.rs @@ -33,7 +33,7 @@ enum Operation { } impl Operation { - pub fn to_char(&self) -> char { + pub const fn to_char(&self) -> char { match self { Self::Intersect => '&', Self::Subtract => '-', @@ -181,8 +181,8 @@ fn compare( )?; for k in key_set_operation_result { - let left_count = left_ordered_counts.get(&k as &str).unwrap_or(&0); - let right_count = right_ordered_counts.get(&k as &str).unwrap_or(&0); + let left_count = left_ordered_counts.get(k as &str).unwrap_or(&0); + let right_count = right_ordered_counts.get(k as &str).unwrap_or(&0); write!( f, @@ -217,7 +217,7 @@ fn compare( fn to_ordered_counts(options: &Options, sels: Vec) -> LinkedHashMap { let mut ret = LinkedHashMap::new(); - for i in sels.into_iter() { + for i in sels { let key = if options.no_trim { i } else { @@ -242,22 +242,22 @@ fn key_set_operation<'a>( ) -> LinkedHashSet<&'a Selection> { match operation { Operation::Intersect => left_keys - .intersection(&right_keys) + .intersection(right_keys) // .into_iter() // TODO: Remove this - .cloned() + .copied() .collect(), Operation::Subtract => left_keys - .difference(&right_keys) + .difference(right_keys) .into_iter() // TODO: Remove this - .cloned() + .copied() .collect(), Operation::Compare | Operation::Union => left_keys - .union(&right_keys) + .union(right_keys) .into_iter() // TODO: Remove this - .cloned() + .copied() .collect(), // TODO: Symmetric difference? } @@ -268,11 +268,11 @@ fn parse_arguments(args: &[String]) -> Result<(Register, Operation, Register), K // They gave us something like "a-b" or "c?d" args.iter() .flat_map(|s: &String| s.trim().chars()) - .map(|c| String::from(c)) + .map(String::from) .collect::>() } else { // They gave us something like "a - b" or "c compare d" - args.iter().cloned().collect() + args.to_vec() }; let (left_register, middle, right_register) = match &args[..] { [l, r] => { @@ -285,9 +285,9 @@ fn parse_arguments(args: &[String]) -> Result<(Register, Operation, Register), K (Ok(_), Ok(_)) => Err(KakError::Custom(format!( "Arguments '{l}' and '{r}' cannot both be operations" ))), - (Err(_), Err(_)) => Err(KakError::Custom(format!( - "One argument must be an operation" - ))), + (Err(_), Err(_)) => Err(KakError::Custom( + "One argument must be an operation".to_string(), + )), } } [l, middle, r] => { @@ -298,9 +298,9 @@ fn parse_arguments(args: &[String]) -> Result<(Register, Operation, Register), K Register::from_str(r)?, )) } - _ => Err(KakError::Custom(format!( - "Invalid arguments to set command" - ))), + _ => Err(KakError::Custom( + "Invalid arguments to set command".to_string(), + )), }?; if left_register == right_register { diff --git a/src/sort.rs b/src/sort.rs index 3274716..50b0b25 100644 --- a/src/sort.rs +++ b/src/sort.rs @@ -104,13 +104,13 @@ fn to_sortable_selection<'a, 'b>( ) -> SortableSelection<'a> { if options.no_skip_whitespace { SortableSelection { - selection: &selection, + selection, content_comparison: selection.content.as_str(), subselections: vec![], } } else { SortableSelection { - selection: &selection, + selection, content_comparison: selection.content.as_str().trim(), subselections: vec![], } diff --git a/src/utils.rs b/src/utils.rs index a0aa8e2..d1de8b4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -5,7 +5,7 @@ use std::{ hash::{Hash, Hasher}, }; -pub(crate) fn get_key( +pub fn get_key( selection: &Selection, skip_whitespace: bool, regex: Option<&Regex>, @@ -40,7 +40,7 @@ pub(crate) fn get_key( } /// Get a key out of a selection based on options -pub(crate) fn get_hash( +pub fn get_hash( selection: &Selection, skip_whitespace: bool, regex: Option<&Regex>,