[][src]Struct krill::commons::util::xml::XmlReader

pub struct XmlReader<R: Read> { /* fields omitted */ }

A convenience wrapper for RPKI XML parsing

This type only exposes things we need for the RPKI XML structures.

Implementations

impl<R: Read> XmlReader<R>[src]

Closure based parsing of XML.

This approach ensures that the consumer can only get opening tags, or content (such as Characters), and process the enclosed content. In particular it ensures that the consumer cannot accidentally get close tags - so it forces that execution returns.

pub fn decode<F, T, E>(source: R, op: F) -> Result<T, E> where
    F: FnOnce(&mut Self) -> Result<T, E>,
    E: From<XmlReaderErr>, 
[src]

Decodes an XML structure

This method checks that the document starts, then passes a reader instance to the provided closure, and will return the result from that after checking that the XML document is fully processed.

pub fn take_element<F, T, E>(&mut self, op: F) -> Result<T, E> where
    F: FnOnce(&Tag, Attributes, &mut Self) -> Result<T, E>,
    E: From<XmlReaderErr>, 
[src]

Takes an element and process it in a closure

This method checks that the next element is indeed a Start Element, and passes the Tag and Attributes and this reader to a closure. After the closure completes it will verify that the next element is the Close Element for this Tag, and returns the result from the closure.

pub fn take_named_element<F, T, E>(&mut self, name: &str, op: F) -> Result<T, E> where
    F: FnOnce(Attributes, &mut Self) -> Result<T, E>,
    E: From<XmlReaderErr>, 
[src]

Takes a named element and process it in a closure

Checks that the element has the expected name and passed the closure to the generic take_element method.

pub fn take_opt_element<F, T, E>(&mut self, op: F) -> Result<Option<T>, E> where
    F: FnOnce(&Tag, Attributes, &mut Self) -> Result<Option<T>, E>,
    E: From<XmlReaderErr>, 
[src]

Takes the next element that is part of a list of elements under the current element, and processes it using a closure. When the end of the list is encountered, i.e. the next element is not a start element, then the closure is not executed and Ok(None) is returned. The element is put back on the cache for processing by the parent structure.

Note: This will break if we encounter a parent XML element that has both a list of children XML elements and some (character) content. However, this is not used by the RPKI XML structures. Also, provided that a 'take_*' method with a closure was used for the parent element, then we will get a clear error there (expect end element).

pub fn take_chars(&mut self) -> Result<String, XmlReaderErr>[src]

Takes characters

pub fn take_bytes_std(&mut self) -> Result<Bytes, XmlReaderErr>[src]

Takes base64 encoded bytes from the next 'characters' event.

pub fn take_empty(&mut self) -> Result<(), XmlReaderErr>[src]

pub fn next_start_name(&mut self) -> Option<&str>[src]

Returns the name of the next start element or None if the next element is not a start element. Also ensures that the next element is kept in the cache for normal subsequent processing.

impl XmlReader<File>[src]

pub fn open<P, F, T, E>(path: P, op: F) -> Result<T, E> where
    F: FnOnce(&mut Self) -> Result<T, E>,
    P: AsRef<Path>,
    E: From<XmlReaderErr> + From<Error>, 
[src]

Opens a file and decodes it as an XML file.

Auto Trait Implementations

impl<R> !RefUnwindSafe for XmlReader<R>

impl<R> Send for XmlReader<R> where
    R: Send

impl<R> Sync for XmlReader<R> where
    R: Sync

impl<R> Unpin for XmlReader<R> where
    R: Unpin

impl<R> !UnwindSafe for XmlReader<R>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.