pub struct Decoder<S> { /* private fields */ }
Expand description
Decodes a name-value tuple into an Event
object using a preconfigured map of
parsers.
Implementations§
source§impl<S> Decoder<S>
impl<S> Decoder<S>
sourcepub fn new(parsers: Vec<Box<dyn NamedEventParser<State = S>>>) -> Self
pub fn new(parsers: Vec<Box<dyn NamedEventParser<State = S>>>) -> Self
sourcepub fn parsers(
&self
) -> impl Iterator<Item = &Box<dyn NamedEventParser<State = S>>>
pub fn parsers(
&self
) -> impl Iterator<Item = &Box<dyn NamedEventParser<State = S>>>
An iterator over the underlying parsers.
sourcepub fn decode(
&self,
name: &str,
encoded: &str
) -> Result<Box<dyn Event<State = S>>, ParseEventError>
pub fn decode(
&self,
name: &str,
encoded: &str
) -> Result<Box<dyn Event<State = S>>, ParseEventError>
Decodes a given encoded
representation for an event of a given name
into a
Event
object.
Errors
ParseEventError
if an event could not be decoded from the given name
and encoded
pair.
Examples found in repository?
src/persistence.rs (line 62)
59 60 61 62 63 64 65 66 67 68 69 70
pub fn decode(self, decoder: &Decoder<S>) -> Result<Scenario<S>, ParseEventError> {
let mut timeline = Vec::with_capacity(self.timeline.len());
for event in self.timeline {
let event = decoder.decode(&event.name, &event.encoded)?;
timeline.push(event);
}
Ok(Scenario {
initial: self.initial,
timeline,
})
}