Struct peepmatic_automata::Builder [−][src]
pub struct Builder<TAlphabet, TState, TOutput> where
TAlphabet: Clone + Eq + Hash + Ord,
TState: Clone + Eq + Hash,
TOutput: Output, { /* fields omitted */ }
Expand description
A builder for a transducer automata.
Type Parameters
Generic over the following parameters:
-
TAlphabet
– the alphabet of the input strings. If your input keys areString
s, this would bechar
. If your input keys are arbitrary byte strings, this would beu8
. -
TState
– extra, custom data associated with each state. This isn’t used by the automata itself, but you can use it to annotate states with extra information for your own purposes. -
TOutput
– the output type. See theOutput
trait for the requirements that any output type must fulfill.
Insertions
Insertions must happen in lexicographic order. Failure to do this, or inserting duplicates, will trigger panics.
Example
use peepmatic_automata::Builder; let mut builder = Builder::<u8, (), u64>::new(); // Insert "mon" -> 1 let mut insertion = builder.insert(); insertion .next(b'm', 1) .next(b'o', 0) .next(b'n', 0); insertion.finish(); // Insert "sat" -> 6 let mut insertion = builder.insert(); insertion .next(b's', 6) .next(b'a', 0) .next(b't', 0); insertion.finish(); // Insert "sun" -> 0 let mut insertion = builder.insert(); insertion .next(b's', 0) .next(b'u', 0) .next(b'n', 0); insertion.finish(); let automata = builder.finish(); assert_eq!(automata.get(b"sun"), Some(0)); assert_eq!(automata.get(b"mon"), Some(1)); assert_eq!(automata.get(b"sat"), Some(6)); assert!(automata.get(b"tues").is_none());
Implementations
impl<TAlphabet, TState, TOutput> Builder<TAlphabet, TState, TOutput> where
TAlphabet: Clone + Eq + Hash + Ord,
TState: Clone + Eq + Hash,
TOutput: Output,
[src]
impl<TAlphabet, TState, TOutput> Builder<TAlphabet, TState, TOutput> where
TAlphabet: Clone + Eq + Hash + Ord,
TState: Clone + Eq + Hash,
TOutput: Output,
[src]pub fn insert(&mut self) -> InsertionBuilder<'_, TAlphabet, TState, TOutput>
[src]
pub fn insert(&mut self) -> InsertionBuilder<'_, TAlphabet, TState, TOutput>
[src]Start building a new key/value insertion.
Insertions are built up incrementally, and a full entry is created from
a series of TAlphabet
and TOutput
pairs passed to
InsertionBuilder::next
.
Panics
Panics if finish
was not called on
the last InsertionBuilder
returned from this method.
pub fn finish(&mut self) -> Automaton<TAlphabet, TState, TOutput>
[src]
pub fn finish(&mut self) -> Automaton<TAlphabet, TState, TOutput>
[src]Finish building this transducer and return the constructed Automaton
.
Panics
Panics if this builder is empty, and has never had anything inserted into it.
Panics if the last insertion’s
InsertionBuilder
did not call its
finish method.
Trait Implementations
Auto Trait Implementations
impl<TAlphabet, TState, TOutput> RefUnwindSafe for Builder<TAlphabet, TState, TOutput> where
TAlphabet: RefUnwindSafe,
TOutput: RefUnwindSafe,
TState: RefUnwindSafe,
TAlphabet: RefUnwindSafe,
TOutput: RefUnwindSafe,
TState: RefUnwindSafe,
impl<TAlphabet, TState, TOutput> Send for Builder<TAlphabet, TState, TOutput> where
TAlphabet: Send,
TOutput: Send,
TState: Send,
TAlphabet: Send,
TOutput: Send,
TState: Send,
impl<TAlphabet, TState, TOutput> Sync for Builder<TAlphabet, TState, TOutput> where
TAlphabet: Sync,
TOutput: Sync,
TState: Sync,
TAlphabet: Sync,
TOutput: Sync,
TState: Sync,
impl<TAlphabet, TState, TOutput> Unpin for Builder<TAlphabet, TState, TOutput> where
TOutput: Unpin,
TState: Unpin,
TOutput: Unpin,
TState: Unpin,
impl<TAlphabet, TState, TOutput> UnwindSafe for Builder<TAlphabet, TState, TOutput> where
TAlphabet: RefUnwindSafe,
TOutput: RefUnwindSafe + UnwindSafe,
TState: RefUnwindSafe + UnwindSafe,
TAlphabet: RefUnwindSafe,
TOutput: RefUnwindSafe + UnwindSafe,
TState: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more