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
sourceimpl 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
sourceimpl Clone for Substitutions
impl Clone for Substitutions
sourcefn clone(&self) -> Substitutions
fn clone(&self) -> Substitutions
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for Substitutions
impl Debug for Substitutions
sourceimpl Default for Substitutions
impl Default for Substitutions
sourcefn default() -> Substitutions
fn default() -> Substitutions
Returns the “default value” for a type. Read more
sourceimpl PartialEq<Substitutions> for Substitutions
impl PartialEq<Substitutions> for Substitutions
sourcefn 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 ==
. Read more
sourcefn ne(&self, other: &Substitutions) -> bool
fn ne(&self, other: &Substitutions) -> bool
This method tests for !=
.
impl Eq for Substitutions
impl StructuralEq for Substitutions
impl StructuralPartialEq for Substitutions
Auto Trait Implementations
impl RefUnwindSafe for Substitutions
impl Send for Substitutions
impl Sync for Substitutions
impl Unpin for Substitutions
impl UnwindSafe for Substitutions
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more