Trait nom::Producer [] [src]

pub trait Producer<'b, I, M: 'b> {
    fn apply<'a, O, E>(&'b mut self, consumer: &'a mut Consumer<I, O, E, M>) -> &'a ConsumerState<O, E, M>;

    fn run<'a: 'b, O, E: 'b>(&'b mut self, consumer: &'a mut Consumer<I, O, E, M>) -> Option<&O> { ... }
}

The producer wraps a data source, like file or network, and applies a consumer on it

it handles buffer copying and reallocation, to provide streaming patterns. it depends on the input type I, and the message type M. the consumer can change the way data is produced (for example, to seek in the source) by sending a message of type M.

Required Methods

Applies a consumer once on the produced data, and return the consumer's state

a new producer has to implement this method.

WARNING: if the ConsumerState generated by your consumer has a reference to the input, it will generate borrow checking errors such as error: cannot borrowproduceras mutable more than once at a time [E0499].

It is caused by the producer's ability to refill the input at will, so it can modify the input slice the ConsumerState is referring to.

To avoid that kind of issue, try to do all the computations on input slices inside the Consumer chain

Provided Methods

Applies a consumer once on the produced data, and returns the generated value if there is one

Implementors