Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clippy lints #10

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::{
},
};

#[derive(Default, Debug, Display, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Default, Debug, Display, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Mode {
#[default]
Expand Down Expand Up @@ -249,7 +249,7 @@ impl App {
let config = config::get();
let action = config
.key_bindings
.event_to_action(&self.mode, &self.last_tick_key_events);
.event_to_action(self.mode, &self.last_tick_key_events);
if action.is_some() {
self.last_tick_key_events.drain(..);
}
Expand Down Expand Up @@ -301,7 +301,7 @@ impl App {
Action::ClosePopup => self.clear_error_and_info_flags(),
Action::ToggleSortBy { reload, forward } => self.toggle_sort_by(reload, forward)?,
Action::ClearTaskDetailsHandle(ref id) => {
self.clear_task_details_handle(uuid::Uuid::parse_str(&id)?)?
self.clear_task_details_handle(uuid::Uuid::parse_str(id)?)?
}
Action::OpenUrlInBrowser => self.open_url_in_browser()?,
_ => {}
Expand Down Expand Up @@ -724,11 +724,7 @@ impl App {
}

fn focused(&self) -> bool {
if self.mode == Mode::Search || self.mode == Mode::Filter {
true
} else {
false
}
matches!(self.mode, Mode::Search | Mode::Filter)
}

fn spinner(&self) -> String {
Expand Down
6 changes: 3 additions & 3 deletions src/crates_io_api_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct SearchParameters {
pub async fn request_crates(params: &SearchParameters) -> Result<(), String> {
// Fetch crates using the created client with the error handling in one place.
let client = create_client()?;
let query = create_query(&params);
let query = create_query(params);
let (crates, versions, total) = fetch_crates_and_metadata(client, query).await?;
update_state_with_fetched_crates(crates, versions, total, params);
Ok(())
Expand Down Expand Up @@ -102,7 +102,7 @@ pub async fn request_crate_details(
let client = create_client()?;

let crate_data = client
.get_crate(&crate_name)
.get_crate(crate_name)
.await
.map_err(|err| format!("Error fetching crate details: {err:#?}"))?;
*crate_info.lock().unwrap() = Some(crate_data);
Expand All @@ -117,7 +117,7 @@ pub async fn request_full_crate_details(
let client = create_client()?;

let full_crate_data = client
.full_crate(&crate_name, false)
.full_crate(crate_name, false)
.await
.map_err(|err| format!("Error fetching crate details: {err:#?}"))?;
*full_crate_info.lock().unwrap() = Some(full_crate_data);
Expand Down
5 changes: 1 addition & 4 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ impl Events {
}

pub async fn next(&mut self) -> Option<Event> {
match self.streams.next().await {
Some((_name, event)) => Some(event),
None => None,
}
self.streams.next().await.map(|(_name, event)| event)
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/serde_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ pub mod keybindings {

impl KeyBindings {
#[allow(dead_code)]
pub fn insert(&mut self, mode: &Mode, key_events: &[KeyEvent], action: Action) {
pub fn insert(&mut self, mode: Mode, key_events: &[KeyEvent], action: Action) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mode impls Copy

// Convert the slice of `KeyEvent`(s) to a `Vec`.
let key_events_vec = key_events.to_vec();

// Retrieve or create the inner `HashMap` corresponding to the mode.
let bindings_for_mode = self.0.entry(mode.clone()).or_insert_with(HashMap::new);
let bindings_for_mode = self.0.entry(mode).or_default();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// Insert the `Action` into the inner `HashMap` using the key events `Vec` as
// the key.
bindings_for_mode.insert(key_events_vec, action);
}

pub fn event_to_action(&self, mode: &Mode, key_events: &[KeyEvent]) -> Option<Action> {
pub fn event_to_action(&self, mode: Mode, key_events: &[KeyEvent]) -> Option<Action> {
if key_events.is_empty() {
None
} else if let Some(Some(action)) = self.0.get(mode).map(|kb| kb.get(key_events)) {
} else if let Some(Some(action)) = self.0.get(&mode).map(|kb| kb.get(key_events)) {
Some(action.clone())
} else {
self.event_to_action(mode, &key_events[1..])
Expand Down Expand Up @@ -86,7 +86,7 @@ pub mod keybindings {
}

fn parse_key_event(raw: &str) -> Result<KeyEvent, String> {
let (remaining, modifiers) = extract_modifiers(&raw);
let (remaining, modifiers) = extract_modifiers(raw);
parse_key_code_with_modifiers(remaining, modifiers)
}

Expand Down