Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fogapod committed Feb 22, 2024
1 parent 3c707d7 commit 6bc6152
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/intensity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct Intensity {
}

impl Intensity {
/// Creates new instance from vec of passes and their names
pub fn new(level: u64, passes: Vec<(String, Pass)>) -> Self {
let (names, passes) = passes.into_iter().unzip();

Expand All @@ -22,7 +23,8 @@ impl Intensity {
}
}

/// Produces new instance by extending inner passes
/// Merges it's own passes with other. Passes for existing names are replaced while new ones
/// are placed at the end of resulting new Intensity
#[allow(clippy::result_large_err)]
pub fn extend(
&self,
Expand Down
8 changes: 6 additions & 2 deletions src/pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ pub struct Pass {
// skips 20 pages of debug output of `multi_regex` field
impl fmt::Debug for Pass {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("UnnamedPass")
f.debug_struct("Pass")
.field("patterns", &self.regexes)
.field("tags", &self.tags)
.finish()
}
}

impl Pass {
/// Creates new instance from vec of regex and tag pairs
#[allow(clippy::result_large_err)]
pub fn new(rules: Vec<(String, Box<dyn Tag>)>) -> Result<Self, CreationError> {
let (patterns, tags): (Vec<_>, Vec<_>) = rules.into_iter().unzip();
Expand All @@ -46,13 +47,15 @@ impl Pass {
})
}

/// Merges it's own regexes with other. Tags for existing regexes are replaced while new ones
/// are placed at the end of resulting new Pass
#[allow(clippy::result_large_err)]
pub fn extend(&self, other: Pass) -> Result<Self, CreationError> {
let mut existing_rules: Vec<_> = self
.regexes
.iter()
.cloned()
.zip(self.tags.iter().cloned())
.zip(self.tags.clone())
.collect();

let mut appended_rules = Vec::new();
Expand All @@ -79,6 +82,7 @@ impl Pass {
Self::new(existing_rules)
}

/// Produces string with all non-overlapping regexes replaced by corresponding tags
pub fn apply<'a>(&self, text: &'a str) -> Cow<'a, str> {
let all_captures: Vec<_> = self.multi_regex.captures_iter(text).collect();

Expand Down

0 comments on commit 6bc6152

Please sign in to comment.