Skip to content

Commit

Permalink
fix: clippy pedantic on lib.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
LoricAndre committed Dec 1, 2024
1 parent 3ff3832 commit e3637e0
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions skim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub trait SkimItem: AsAny + Send + Sync + 'static {
}

/// we could limit the matching ranges of the `get_text` of the item.
/// providing (start_byte, end_byte) of the range
/// providing (`start_byte`, `end_byte`) of the range
fn get_matching_ranges(&self) -> Option<&[(usize, usize)]> {
None
}
Expand Down Expand Up @@ -174,12 +174,14 @@ impl<'a> From<DisplayContext<'a>> for AnsiString<'a> {
fn from(context: DisplayContext<'a>) -> Self {
match context.matches {
Matches::CharIndices(indices) => AnsiString::from((context.text, indices, context.highlight_attr)),
#[allow(clippy::cast_possible_truncation)]
Matches::CharRange(start, end) => {
AnsiString::new_str(context.text, vec![(context.highlight_attr, (start as u32, end as u32))])
}
Matches::ByteRange(start, end) => {
let ch_start = context.text[..start].chars().count();
let ch_end = ch_start + context.text[start..end].chars().count();
#[allow(clippy::cast_possible_truncation)]
AnsiString::new_str(
context.text,
vec![(context.highlight_attr, (ch_start as u32, ch_end as u32))],
Expand Down Expand Up @@ -259,6 +261,7 @@ pub struct MatchResult {
}

impl MatchResult {
#[must_use]
pub fn range_char_indices(&self, text: &str) -> Vec<usize> {
match &self.matched_range {
&MatchRange::ByteRange(start, end) => {
Expand Down Expand Up @@ -297,14 +300,21 @@ pub type SkimItemReceiver = Receiver<Arc<dyn SkimItem>>;
pub struct Skim {}

impl Skim {
/// params:
/// # Params
///
/// - options: the "complex" options that control how skim behaves
/// - source: a stream of items to be passed to skim for filtering.
/// If None is given, skim will invoke the command given to fetch the items.
///
/// return:
/// # Returns
///
/// - None: on internal errors.
/// - SkimOutput: the collected key, event, query, selected items, etc.
/// - `SkimOutput`: the collected key, event, query, selected items, etc.
///
/// # Panics
///
/// Panics if the tui fails to initilize
#[must_use]
pub fn run_with(options: &SkimOptions, source: Option<SkimItemReceiver>) -> Option<SkimOutput> {
let min_height = Skim::parse_height_string(&options.min_height);
let height = Skim::parse_height_string(&options.height);
Expand All @@ -329,8 +339,8 @@ impl Skim {
//------------------------------------------------------------------------------
// input
let mut input = input::Input::new();
input.parse_keymaps(options.bind.iter().map(|s| s.as_str()));
input.parse_expect_keys(options.expect.iter().map(|s| s.as_str()));
input.parse_keymaps(options.bind.iter().map(String::as_str));
input.parse_expect_keys(options.expect.iter().map(String::as_str));

let tx_clone = tx.clone();
let term_clone = term.clone();
Expand All @@ -341,7 +351,7 @@ impl Skim {
}

let (key, action_chain) = input.translate_event(key);
for event in action_chain.into_iter() {
for event in action_chain {
let _ = tx_clone.send((key, event));
}
}
Expand Down

0 comments on commit e3637e0

Please sign in to comment.