Struct snapbox::Substitutions
source · pub struct Substitutions { /* private fields */ }
Expand description
Match pattern expressions, see Assert
Built-in expressions:
...
on a line of its own: match multiple complete lines[..]
: match multiple characters within a line
Implementations§
source§impl Substitutions
impl Substitutions
pub fn new() -> Self
sourcepub fn insert(
&mut self,
key: &'static str,
value: impl Into<Cow<'static, str>>
) -> Result<(), Error>
pub fn insert(
&mut self,
key: &'static str,
value: impl Into<Cow<'static, str>>
) -> Result<(), Error>
Insert an additional match pattern
key
must be enclosed in [
and ]
.
let mut subst = snapbox::Substitutions::new();
subst.insert("[EXE]", std::env::consts::EXE_SUFFIX);
sourcepub fn extend(
&mut self,
vars: impl IntoIterator<Item = (&'static str, impl Into<Cow<'static, str>>)>
) -> Result<(), Error>
pub fn extend(
&mut self,
vars: impl IntoIterator<Item = (&'static str, impl Into<Cow<'static, str>>)>
) -> Result<(), Error>
Insert additional match patterns
keys must be enclosed in [
and ]
.
sourcepub fn normalize(&self, input: &str, pattern: &str) -> String
pub fn normalize(&self, input: &str, pattern: &str) -> String
Apply match pattern to input
If pattern
matches input
, then pattern
is returned.
Otherwise, input
, with as many patterns replaced as possible, will be returned.
let subst = snapbox::Substitutions::new();
let output = subst.normalize("Hello World!", "Hello [..]!");
assert_eq!(output, "Hello [..]!");
Trait Implementations§
source§impl Clone for Substitutions
impl Clone for Substitutions
source§fn clone(&self) -> Substitutions
fn clone(&self) -> Substitutions
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for Substitutions
impl Debug for Substitutions
source§impl Default for Substitutions
impl Default for Substitutions
source§fn default() -> Substitutions
fn default() -> Substitutions
Returns the “default value” for a type. Read more
source§impl PartialEq<Substitutions> for Substitutions
impl PartialEq<Substitutions> for Substitutions
source§fn eq(&self, other: &Substitutions) -> bool
fn eq(&self, other: &Substitutions) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.