Trait regex::bytes::Replacer
[−]
[src]
pub trait Replacer { fn replace_append(&mut self, caps: &Captures, dst: &mut Vec<u8>); fn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, [u8]>> { ... } }
Replacer describes types that can be used to replace matches in a byte string.
In general, users of this crate shouldn't need to implement this trait,
since implementations are already provided for &[u8]
and
FnMut(&Captures) -> Vec<u8>
, which covers most use cases.
Required Methods
fn replace_append(&mut self, caps: &Captures, dst: &mut Vec<u8>)
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[0])
.
Provided Methods
fn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, [u8]>>
Return a fixed unchanging replacement byte 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
.