Struct finl_charsub::charsub::CharSubMachine[][src]

pub struct CharSubMachine { /* fields omitted */ }
Expand description

The implementation of a char substitution machine. This is a non-thread-safe implementation with mutable state.

Implementations

Create a new blank char substitution machine.

Create a new blank char substitution machine instantiated from the specified file (given as a std::io::buffered::BufReader. Since errors might occur during the read process, the result is wrapped in anyhow::Result. Errors can be of type CharSubError, UnescapeError or io::Error depending on the origin of the error.

Add a new substitution rule to an existing char sub machine. This will not fail.

Process an input string and return the substitution in alloc::borrow::Cow<str>. This will not fail, but may leave unprocessed output behind if the end of the string might be part pf a longer substitution, e.g..

let mut char_sub_machine = CharSubMachine::new();

char_sub_machine.add_substitution("A", "a");
char_sub_machine.add_substitution("ABC", "b");

assert_eq!("", char_sub_machine.process("AB"));
assert_eq!("b", char_sub_machine.process("C"));

Returns a possibly empty string with the contents of any unprocessed input still waiting in the unprocessed buffer.

let mut char_sub_machine = CharSubMachine::new();

char_sub_machine.add_substitution("A", "a");
char_sub_machine.add_substitution("ABC", "b");

assert_eq!("", char_sub_machine.process("AB"));
assert_eq!("aB".to_string(), char_sub_machine.flush());

assert_eq!("b", char_sub_machine.process("ABC"));
assert_eq!("".to_string(), char_sub_machine.flush());

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.