Skip to main content

Visitor

Trait Visitor 

Source
pub trait Visitor<'a> {
    // Required methods
    fn item(&mut self, bare: BareItem<'a>) -> Result<(), ParseError>;
    fn param(
        &mut self,
        key: &'a str,
        value: BareItem<'a>,
    ) -> Result<(), ParseError>;

    // Provided methods
    fn inner_list_start(&mut self) -> Result<(), ParseError> { ... }
    fn inner_list_end(&mut self) -> Result<(), ParseError> { ... }
    fn key(&mut self, key: &'a str) -> Result<(), ParseError> { ... }
}
Expand description

Receives a parse as events: the single-pass form, for callers that read one key or count items without building a view.

§Examples

use parse_net::{sfv::{BareItem, Parser, Visitor}, Limits, ParseError};

struct Urgency(Option<i64>, bool);
impl<'a> Visitor<'a> for Urgency {
    fn item(&mut self, bare: BareItem<'a>) -> Result<(), ParseError> {
        if let (true, BareItem::Integer(u)) = (self.1, bare) { self.0 = Some(u); }
        Ok(())
    }
    fn param(&mut self, _: &'a str, _: BareItem<'a>) -> Result<(), ParseError> { Ok(()) }
    fn key(&mut self, key: &'a str) -> Result<(), ParseError> { self.1 = key == "u"; Ok(()) }
}

let mut v = Urgency(None, false);
Parser::new(Limits::DEFAULT).visit_dictionary(b"u=5, i", &mut v)?;
assert_eq!(v.0, Some(5));

Required Methods§

Source

fn item(&mut self, bare: BareItem<'a>) -> Result<(), ParseError>

A bare item: a member, an inner-list item, or a dictionary value.

§Errors

Any error stops the parse and is returned.

Source

fn param(&mut self, key: &'a str, value: BareItem<'a>) -> Result<(), ParseError>

A parameter of the most recent item or inner list.

§Errors

Any error stops the parse and is returned.

Provided Methods§

Source

fn inner_list_start(&mut self) -> Result<(), ParseError>

An inner list begins.

§Errors

Any error stops the parse and is returned.

Source

fn inner_list_end(&mut self) -> Result<(), ParseError>

An inner list ends (its parameters follow).

§Errors

Any error stops the parse and is returned.

Source

fn key(&mut self, key: &'a str) -> Result<(), ParseError>

A dictionary key; its value follows.

§Errors

Any error stops the parse and is returned.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§