diff --git a/rslib/src/tags/matcher.rs b/rslib/src/tags/matcher.rs index 3f7ded47e..2cc3a0850 100644 --- a/rslib/src/tags/matcher.rs +++ b/rslib/src/tags/matcher.rs @@ -6,7 +6,6 @@ use std::{borrow::Cow, collections::HashSet}; use regex::{Captures, Regex}; use super::{join_tags, split_tags}; -use crate::prelude::*; pub(crate) struct TagMatcher { regex: Regex, new_tags: HashSet, @@ -17,7 +16,7 @@ pub(crate) struct TagMatcher { /// /// Tracks seen tags during replacement, so the tag list can be updated as well. impl TagMatcher { - pub fn new(space_separated_tags: &str) -> Result { + pub fn new(space_separated_tags: &str) -> Self { // convert "fo*o bar" into "fo\*o|bar" let tags: Vec<_> = split_tags(space_separated_tags) .map(regex::escape) @@ -40,12 +39,13 @@ impl TagMatcher { ) "#, tags - ))?; + )) + .unwrap(); - Ok(Self { + Self { regex, new_tags: HashSet::new(), - }) + } } pub fn is_match(&self, space_separated_tags: &str) -> bool { @@ -129,13 +129,13 @@ mod test { use super::*; #[test] - fn regex() -> Result<()> { - let re = TagMatcher::new("one two")?; + fn regex() { + let re = TagMatcher::new("one two"); assert!(!re.is_match(" foo ")); assert!(re.is_match(" foo one ")); assert!(re.is_match(" two foo ")); - let mut re = TagMatcher::new("foo")?; + let mut re = TagMatcher::new("foo"); assert!(re.is_match("foo")); assert!(re.is_match(" foo ")); assert!(re.is_match(" bar foo baz ")); @@ -155,7 +155,5 @@ mod test { &as_xxx(" x foo::bar foo::bar::baz x "), " x xxx::bar xxx::bar::baz x " ); - - Ok(()) } } diff --git a/rslib/src/tags/remove.rs b/rslib/src/tags/remove.rs index d43b401d7..0577d50d7 100644 --- a/rslib/src/tags/remove.rs +++ b/rslib/src/tags/remove.rs @@ -32,7 +32,7 @@ impl Collection { let usn = self.usn()?; // gather tags that need removing - let mut re = TagMatcher::new(tags)?; + let mut re = TagMatcher::new(tags); let matched_notes = self .storage .get_note_tags_by_predicate(|tags| re.is_match(tags))?; @@ -57,7 +57,7 @@ impl Collection { fn remove_tags_from_notes_inner(&mut self, nids: &[NoteId], tags: &str) -> Result { let usn = self.usn()?; - let mut re = TagMatcher::new(tags)?; + let mut re = TagMatcher::new(tags); let mut match_count = 0; let notes = self.storage.get_note_tags_by_id_list(nids)?; diff --git a/rslib/src/tags/rename.rs b/rslib/src/tags/rename.rs index 253a62cd9..1de297a1a 100644 --- a/rslib/src/tags/rename.rs +++ b/rslib/src/tags/rename.rs @@ -39,7 +39,7 @@ impl Collection { .unwrap_or(new_prefix); // gather tags that need replacing - let mut re = TagMatcher::new(old_prefix)?; + let mut re = TagMatcher::new(old_prefix); let matched_notes = self .storage .get_note_tags_by_predicate(|tags| re.is_match(tags))?; diff --git a/rslib/src/tags/reparent.rs b/rslib/src/tags/reparent.rs index bdedd38b0..af45822db 100644 --- a/rslib/src/tags/reparent.rs +++ b/rslib/src/tags/reparent.rs @@ -36,7 +36,7 @@ impl Collection { new_parent: Option, ) -> Result { let usn = self.usn()?; - let mut matcher = TagMatcher::new(&join_tags(tags_to_reparent))?; + let mut matcher = TagMatcher::new(&join_tags(tags_to_reparent)); let old_to_new_names = old_to_new_names(tags_to_reparent, new_parent); let matched_notes = self