Trait Visitor

Source
pub trait Visitor<B: AsyncBufRead + Unpin> {
    type Output;

    // Required method
    fn build(self) -> Result<Self::Output, Error>;

    // Provided methods
    fn start_name() -> Option<&'static str> { ... }
    fn visit_tag(&mut self, name: &str) -> Result<(), Error> { ... }
    fn visit_attribute(&mut self, name: &str, value: &str) -> Result<(), Error> { ... }
    fn visit_child<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        name: &'life1 str,
        reader: &'life2 mut PeekingReader<B>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn visit_text(&mut self, text: &str) -> Result<(), Error> { ... }
}
Expand description

A trait for building up instances of types during deserialization

As XmlReader::read_event_into_async() does not return a Send future, this entire trait must be ?Send.

Required Associated Types§

Source

type Output

Output type this Visitor returns

Required Methods§

Source

fn build(self) -> Result<Self::Output, Error>

Validate and build the output type

Provided Methods§

Source

fn start_name() -> Option<&'static str>

Should return the expected starting tag name, if any

Source

fn visit_tag(&mut self, name: &str) -> Result<(), Error>

Visit the starting tag with the given name

This is called exactly once during deserialization and will be called before any other visit_* methods.

Source

fn visit_attribute(&mut self, name: &str, value: &str) -> Result<(), Error>

Visit an attribute with the given name and value

Source

fn visit_child<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, name: &'life1 str, reader: &'life2 mut PeekingReader<B>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Visit a child element with the given tag name

Implementations must make sure the child element is read in some way. Most likely this will be either a reader.skip_element() or reader.deserialize() call.

Source

fn visit_text(&mut self, text: &str) -> Result<(), Error>

Visit any plain text contained in the element

May be called multiple times.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<B> Visitor<B> for XmlNode
where B: AsyncBufRead + Unpin,

Source§

impl<B, T> Visitor<B> for OptionalVisitor<T, B>
where B: AsyncBufRead + Unpin, T: FromXml<B>,

Source§

impl<B, T, E> Visitor<B> for FromStringVisitor<T>
where B: AsyncBufRead + Unpin, T: XmlFromStr + FromStr<Err = E>, E: Display,

Source§

impl<B, Target, FromType> Visitor<B> for FromVisitor<B, Target, FromType>
where B: AsyncBufRead + Unpin, Target: From<FromType>, FromType: FromXml<B>,

Source§

type Output = Target

Source§

impl<B, Target, FromType, E> Visitor<B> for TryFromVisitor<B, Target, FromType, E>
where B: AsyncBufRead + Unpin, Target: TryFrom<FromType, Error = E>, FromType: FromXml<B>, E: Display,

Source§

type Output = Target

Source§

impl<V, B> Visitor<B> for DiscardErrorVisitor<V, B>
where B: AsyncBufRead + Unpin, V: Visitor<B>,

Source§

type Output = Option<<V as Visitor<B>>::Output>