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 */ }

A builder for a transducer automata.

Type Parameters

Generic over the following parameters:

  • TAlphabet -- the alphabet of the input strings. If your input keys are Strings, this would be char. If your input keys are arbitrary byte strings, this would be u8.

  • 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 the Output 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]

pub fn new() -> Self[src]

Make a new builder to start constructing a new transducer automata.

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]

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

impl<TAlphabet: Clone, TState: Clone, TOutput: Clone> Clone for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: Clone + Eq + Hash + Ord,
    TState: Clone + Eq + Hash,
    TOutput: Output
[src]

impl<TAlphabet: Debug, TState: Debug, TOutput: Debug> Debug for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: Clone + Eq + Hash + Ord,
    TState: Clone + Eq + Hash,
    TOutput: Output
[src]

Auto Trait Implementations

impl<TAlphabet, TState, TOutput> RefUnwindSafe for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: RefUnwindSafe,
    TOutput: RefUnwindSafe,
    TState: RefUnwindSafe
[src]

impl<TAlphabet, TState, TOutput> Send for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: Send,
    TOutput: Send,
    TState: Send
[src]

impl<TAlphabet, TState, TOutput> Sync for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: Sync,
    TOutput: Sync,
    TState: Sync
[src]

impl<TAlphabet, TState, TOutput> Unpin for Builder<TAlphabet, TState, TOutput> where
    TOutput: Unpin,
    TState: Unpin
[src]

impl<TAlphabet, TState, TOutput> UnwindSafe for Builder<TAlphabet, TState, TOutput> where
    TAlphabet: RefUnwindSafe,
    TOutput: RefUnwindSafe + UnwindSafe,
    TState: RefUnwindSafe + UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.