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 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

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

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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 resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.