Skip to content

Commit

Permalink
apply clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
micielski committed Jul 14, 2024
1 parent 65f33ef commit 9e87c12
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 127 deletions.
8 changes: 4 additions & 4 deletions rm-config/src/keymap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl<'de, T: Into<Action> + Deserialize<'de>> Deserialize<'de> for Keybinding<T>
"Keybinding",
FIELDS,
KeybindingVisitor {
phantom: PhantomData::default(),
phantom: PhantomData,
},
)
}
Expand Down Expand Up @@ -266,14 +266,14 @@ impl KeymapConfig {
match utils::fetch_config::<Self>(Self::FILENAME) {
Ok(mut keymap_config) => {
keymap_config.populate_hashmap();
return Ok(keymap_config);
Ok(keymap_config)
}
Err(e) => match e {
utils::ConfigFetchingError::Io(e) if e.kind() == ErrorKind::NotFound => {
let mut keymap_config =
utils::put_config::<Self>(Self::DEFAULT_CONFIG, Self::FILENAME)?;
keymap_config.populate_hashmap();
return Ok(keymap_config);
Ok(keymap_config)
}
_ => anyhow::bail!(e),
},
Expand All @@ -295,7 +295,7 @@ impl KeymapConfig {
}

if keys.is_empty() {
return None;
None
} else {
Some(keys.join("/"))
}
Expand Down
4 changes: 2 additions & 2 deletions rm-config/src/main_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl MainConfig {

pub(crate) fn init() -> Result<Self> {
match utils::fetch_config::<Self>(Self::FILENAME) {
Ok(config) => return Ok(config),
Ok(config) => Ok(config),
Err(e) => match e {
utils::ConfigFetchingError::Io(e) if e.kind() == ErrorKind::NotFound => {
utils::put_config::<Self>(Self::DEFAULT_CONFIG, Self::FILENAME)?;
Expand All @@ -153,7 +153,7 @@ impl MainConfig {
}
_ => anyhow::bail!(e),
},
};
}
}

pub(crate) fn path() -> &'static PathBuf {
Expand Down
21 changes: 10 additions & 11 deletions rm-main/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ impl Ctx {
match response {
Ok(res) => {
let session_info = Arc::new(res.arguments);
return Ok(Self {
Ok(Self {
config: Arc::new(config),
action_tx,
trans_tx,
update_tx,
session_info,
});
})
}
Err(e) => {
let config_path = config.directories.main_path;
return Err(Error::msg(format!(
Err(Error::msg(format!(
"{e}\nIs the connection info in {:?} correct?",
config_path
)));
)))
}
}
}
Expand Down Expand Up @@ -161,12 +161,13 @@ impl App {
async fn handle_user_action(&mut self, action: Action) {
use Action as A;
match &action {

A::HardQuit => {
self.should_quit = true;
}

_ => {self.main_window.handle_actions(action);},
_ => {
self.main_window.handle_actions(action);
}
}
}

Expand All @@ -175,15 +176,13 @@ impl App {
UpdateAction::SwitchToInputMode => {
self.mode = Mode::Input;
self.ctx.send_action(Action::Render);
},
}
UpdateAction::SwitchToNormalMode => {
self.mode = Mode::Normal;
self.ctx.send_action(Action::Render);
},

UpdateAction::TaskClear => {
self.main_window.handle_update_action(action)
}

UpdateAction::TaskClear => self.main_window.handle_update_action(action),
}
}
}
4 changes: 2 additions & 2 deletions rm-main/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub async fn handle_command(config: &Config, command: Commands) -> Result<()> {
}

async fn add_torrent(config: &Config, torrent: String) -> Result<()> {
let mut transclient = transmission::utils::client_from_config(&config);
let mut transclient = transmission::utils::client_from_config(config);
let args = {
if torrent.starts_with("magnet:")
|| torrent.starts_with("http:")
Expand Down Expand Up @@ -70,7 +70,7 @@ async fn add_torrent(config: &Config, torrent: String) -> Result<()> {
}

async fn fetch_rss(config: &Config, url: &str, filter: Option<&str>) -> Result<()> {
let mut transclient = transmission::utils::client_from_config(&config);
let mut transclient = transmission::utils::client_from_config(config);
let content = reqwest::get(url).await?.bytes().await?;
let channel = rss::Channel::read_from(&content[..])?;
let re: Option<Regex> = {
Expand Down
4 changes: 2 additions & 2 deletions rm-main/src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ impl Tui {
let crossterm_event = reader.next().fuse();
tokio::select! {
_ = cancellation_token.cancelled() => break,
event = crossterm_event => Self::handle_crossterm_event::<io::Error>(event, &event_tx)?,
event = crossterm_event => Self::handle_crossterm_event(event, &event_tx)?,
}
}
Ok(())
});
Ok(())
}

fn handle_crossterm_event<T>(
fn handle_crossterm_event(
event: Option<Result<Event, io::Error>>,
event_tx: &UnboundedSender<Event>,
) -> Result<()> {
Expand Down
6 changes: 2 additions & 4 deletions rm-main/src/ui/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rm_shared::action::Action;
use rm_shared::action::UpdateAction;
pub use tabs::TabComponent;

#[derive(Clone, Copy,PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum ComponentAction {
Nothing,
Quit,
Expand All @@ -29,7 +29,5 @@ pub trait Component {

fn render(&mut self, _f: &mut Frame, _rect: Rect) {}

fn tick(&mut self) {
()
}
fn tick(&mut self) {}
}
12 changes: 2 additions & 10 deletions rm-main/src/ui/components/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,8 @@ impl Component for TabComponent {
2 => self.current_tab = CurrentTab::Search,
_ => (),
},
// left only works on right-most tab (search)
Action::Left => match self.current_tab {
CurrentTab::Search => self.current_tab = CurrentTab::Torrents,
_ => (),
},
// right only works on left-most tab (torrents)
Action::Right => match self.current_tab {
CurrentTab::Torrents => self.current_tab = CurrentTab::Search,
_ => (),
},
Action::Left => self.current_tab = CurrentTab::Torrents,
Action::Right => self.current_tab = CurrentTab::Search,
_ => (),
}
ComponentAction::Nothing
Expand Down
22 changes: 11 additions & 11 deletions rm-main/src/ui/tabs/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ impl SearchTab {
])
}

#[must_use]
fn change_focus(&mut self) {
if self.search_focus == SearchFocus::Search {
self.search_focus = SearchFocus::List;
Expand Down Expand Up @@ -121,11 +120,13 @@ impl SearchTab {
KeyCode::Enter => {
self.req_sender.send(self.input.to_string()).unwrap();
self.search_focus = SearchFocus::List;
self.ctx.send_update_action(UpdateAction::SwitchToNormalMode);
self.ctx
.send_update_action(UpdateAction::SwitchToNormalMode);
}
KeyCode::Esc => {
self.search_focus = SearchFocus::List;
self.ctx.send_update_action(UpdateAction::SwitchToNormalMode);
self.ctx
.send_update_action(UpdateAction::SwitchToNormalMode);
}
_ => {
if let Some(req) = to_input_request(input) {
Expand Down Expand Up @@ -193,7 +194,9 @@ impl Component for SearchTab {
A::Home => self.scroll_to_home(),
A::End => self.scroll_to_end(),
A::Confirm => self.add_torrent(),
A::Tick => {self.tick();},
A::Tick => {
self.tick();
}

_ => (),
};
Expand Down Expand Up @@ -329,7 +332,7 @@ impl SearchResultState {
impl Component for SearchResultState {
fn render(&mut self, f: &mut Frame, rect: Rect) {
match &self.status {
SearchResultStatus::Nothing => return,
SearchResultStatus::Nothing => (),
SearchResultStatus::Searching(state) => {
let default_throbber = throbber_widgets_tui::Throbber::default()
.label("Searching...")
Expand Down Expand Up @@ -358,12 +361,9 @@ impl Component for SearchResultState {
}

fn tick(&mut self) {
match &self.status {
SearchResultStatus::Searching(state) => {
state.lock().unwrap().calc_next();
self.ctx.send_action(Action::Render);
}
_ => (),
if let SearchResultStatus::Searching(state) = &self.status {
state.lock().unwrap().calc_next();
self.ctx.send_action(Action::Render);
}
}
}
15 changes: 7 additions & 8 deletions rm-main/src/ui/tabs/torrents/input_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ impl Component for InputManager {
fn render(&mut self, f: &mut Frame, rect: Rect) {
f.render_widget(Clear, rect);

let mut spans = vec![];

spans.push(Span::styled(
self.prompt.as_str(),
Style::default().fg(self.ctx.config.general.accent_color),
));

spans.push(Span::raw(self.text()));
let spans = vec![
Span::styled(
self.prompt.as_str(),
Style::default().fg(self.ctx.config.general.accent_color),
),
Span::raw(self.text()),
];

let input = self.input.to_string();
let prefix_len = self.prompt.len() + self.text().len() - input.len();
Expand Down
4 changes: 2 additions & 2 deletions rm-main/src/ui/tabs/torrents/rustmission_torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct RustmissionTorrent {
}

impl RustmissionTorrent {
pub fn to_row(&self, headers: &Vec<Header>) -> ratatui::widgets::Row {
pub fn to_row(&self, headers: &[Header]) -> ratatui::widgets::Row {
headers
.iter()
.map(|header| self.header_to_line(*header))
Expand Down Expand Up @@ -59,7 +59,7 @@ impl RustmissionTorrent {

for header in headers {
if *header == Header::Name {
cells.push(Line::from(torrent_name_line.clone()))
cells.push(torrent_name_line.clone())
} else {
cells.push(self.header_to_line(*header))
}
Expand Down
2 changes: 1 addition & 1 deletion rm-main/src/ui/tabs/torrents/table_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl TableManager {
let headers = &self.ctx.config.torrents_tab.headers;

if !self.ctx.config.general.auto_hide {
return Self::default_widths(&headers);
return Self::default_widths(headers);
}

let mut map = HashMap::new();
Expand Down
Loading

0 comments on commit 9e87c12

Please sign in to comment.