[][src]Trait regex::Replacer

pub trait Replacer {
    fn replace_append(&mut self, caps: &Captures, dst: &mut String);

    fn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, str>> { ... }
}

Replacer describes types that can be used to replace matches in a string.

In general, users of this crate shouldn't need to implement this trait, since implementations are already provided for &str and FnMut(&Captures) -> String, which covers most use cases.

Required methods

fn replace_append(&mut self, caps: &Captures, dst: &mut String)

Appends text to dst to replace the current match.

The current match is represented by caps, which is guaranteed to have a match at capture group 0.

For example, a no-op replacement would be dst.extend(caps.get(0).unwrap().as_str()).

Loading content...

Provided methods

fn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, str>>

Return a fixed unchanging replacement string.

When doing replacements, if access to Captures is not needed (e.g., the replacement byte string does not need $ expansion), then it can be beneficial to avoid finding sub-captures.

In general, this is called once for every call to replacen.

Loading content...

Implementations on Foreign Types

impl<'a> Replacer for &'a str[src]

Loading content...

Implementors

impl<'t> Replacer for NoExpand<'t>[src]

impl<F> Replacer for F where
    F: FnMut(&Captures) -> String
[src]

Loading content...