Skip to content

Commit

Permalink
apply optimizations suggested by cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
jooooscha committed Jan 29, 2024
1 parent bf9fca3 commit aa9db07
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
16 changes: 4 additions & 12 deletions src/backend/data/channel_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,16 @@ impl ChannelList {

/// Filter all channels that are not in the UrlFile anymore
fn remove_old(&mut self, url_file: &Subscriptions) {
self.channels = self
.channels
.iter()
.filter(|channel| url_file.contains_channel_by_id(channel.id()))
.cloned()
.collect();
self.channels
.retain(|channel| url_file.contains_channel_by_id(channel.id()));

// remove videos that belong to urls removed from a custom channel
for custom_channel in url_file.custom_channels.iter() {
let urls = &custom_channel.urls;

if let Some(mut channel) = self.get_mut_by_id(&custom_channel.id()) {
channel.videos = channel
.videos
.iter()
.filter(|video| urls.contains(video.origin_url()))
.cloned()
.collect();
channel.videos
.retain(|video| urls.contains(video.origin_url()));
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/backend/data/feed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,8 @@ impl Feed {
}

pub fn filter_videos(&mut self, block_regex: Regex) {
self.videos = self.videos
.iter()
.filter(|&video| {
// eprintln!("{}, {:?}", video.get_title(), block_regex);
! block_regex.is_match(video.get_title()).unwrap()
})
.cloned()
.collect();
self.videos
.retain(|video| { ! block_regex.is_match(video.get_title()).unwrap() });
}

pub fn add_videos(&mut self, videos: Vec<VideoBuilder>) {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/io/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct MinimalVideo {
impl ToTuiListItem for MinimalVideo {
fn to_list_item(&self) -> ListItem {
let channel = format!("{} {} - ", tui::symbols::DOT, &self.channel);
let title = (&self.title).to_string();
let title = self.title.clone();

let style = Style::default().fg(Color::DarkGray);

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() -> Result<(), Error> {
match core.get_current_screen() {
Channels => {}
Videos => {
let _ = core.action(Leave);
core.action(Leave);
}
}
core.draw();
Expand Down Expand Up @@ -86,7 +86,7 @@ fn main() -> Result<(), Error> {
Key::Char('\n') | Key::Char('l') | Key::Right | Key::Char('o') => {
match core.get_current_screen() {
Channels => {
let _ = core.action(Enter);
core.action(Enter);
}
Videos => {
core.action(Open);
Expand Down

0 comments on commit aa9db07

Please sign in to comment.