Skip to content

Commit

Permalink
Refactor unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
quambene committed Jan 22, 2024
1 parent d131f3e commit dd14fd1
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/bookmarks/target_bookmarks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use super::{Action, JsonBookmark};
use crate::{cache::CacheMode, SourceBookmark, SourceBookmarks, SourceType, UnderlyingType};
use crate::{
cache::CacheMode, errors::BogrepError, SourceBookmark, SourceBookmarks, SourceType,
UnderlyingType,
};
use chrono::{DateTime, Utc};
use log::{debug, trace};
use log::{debug, trace, warn};
use std::collections::{
hash_map::{Entry, IntoIter, IntoValues, Iter, IterMut, Keys, Values, ValuesMut},
HashMap, HashSet,
Expand Down Expand Up @@ -212,11 +215,21 @@ impl TargetBookmarks {
&self,
source_bookmarks: &'a SourceBookmarks,
) -> Vec<&'a SourceBookmark> {
// TODO: refactor unwrap
source_bookmarks
.iter()
.filter(|(url, _)| !self.0.contains_key(&Url::parse(url).unwrap()))
.map(|(_, bookmark)| bookmark)
.filter_map(|(url, bookmark)| match Url::parse(url) {
Ok(url) => {
if !self.0.contains_key(&url) {
Some(bookmark)
} else {
None
}
}
Err(err) => {
warn!("{}", BogrepError::ParseUrl(err));
None

Check warning on line 230 in src/bookmarks/target_bookmarks.rs

View check run for this annotation

Codecov / codecov/patch

src/bookmarks/target_bookmarks.rs#L228-L230

Added lines #L228 - L230 were not covered by tests
}
})
.collect()
}

Expand Down

0 comments on commit dd14fd1

Please sign in to comment.