Skip to main content

Substitutor

Trait Substitutor 

Source
pub trait Substitutor {
    // Required methods
    fn new() -> Self;
    fn gsub<'a>(&self, s: &'a str) -> Cow<'a, str>;
    fn add(
        &mut self,
        pattern: &str,
        repl: String,
        limit: usize,
    ) -> Result<(), SubstitutorAddError>;
}
Expand description

The substitutor implementing the gsub function in tphrase. You can replace the default into your version. Generator doesn’t have Clone and Debug traits if your instance of Substitutor doesn’t have Clone and Debug traits.

Required Methods§

Source

fn new() -> Self

Create a substitutor. Used in parse(), parse_str(), Generator::from_str(), and Syntax::from_str().

Source

fn gsub<'a>(&self, s: &'a str) -> Cow<'a, str>

Substitute str. Used in Generator::generate().

Source

fn add( &mut self, pattern: &str, repl: String, limit: usize, ) -> Result<(), SubstitutorAddError>

Add an instruction of gsub function. Used in parsing.

The string in Err is the error message to show users.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§