Struct Parser

Source
pub struct Parser { /* private fields */ }
Expand description

§Non-blocking restricted XML 1.0 parser

The Parser allows parsing XML documents as they arrive in the application, giving back control to the caller immediately when not enough data is available for processing. This is especially useful when streaming data from sockets.

To read events from the Parser after feeding data, use its Parse trait.

§Example

use rxml::{Parser, Parse, Error, Event, XmlVersion, error::EndOrError};
let doc = b"<?xml version='1.0'?><hello>World!</hello>";
let mut fp = Parser::new();
// We expect a NeedMoreData, because the XML declaration is not complete yet
assert!(matches!(
	fp.parse(&mut &doc[..10], false).err().unwrap(),
	EndOrError::NeedMoreData,
));

// Now we pass the XML declaration (and some), so we expect a corresponding
// event
let ev = fp.parse(&mut &doc[10..25], false);
assert!(matches!(ev.unwrap().unwrap(), Event::XmlDeclaration(_, XmlVersion::V1_0)));

In contrast to a RawParser, the Parser enforces well-formedness and namespace-well-formedness.

Implementations§

Source§

impl Parser

Source

pub fn new() -> Self

Create a new parser with default settings.

Source

pub fn set_text_buffering(&mut self, enabled: bool)

Configure text buffering (enabled by default).

If enabled, text content is buffered up to the configured token size limit, unless it is more efficient to flush it out anyway.

If disabled, text content is emitted as event as soon as at least one valid char has been read.

Enabling text buffering reduces the number of calls which need to be made into the parser and thus may improve performance. However, it also makes the application see the text content later, which may be problematic if control flow which affects parsing depends on text content.

Source

pub fn text_buffering(&self) -> bool

Return whether text buffering is enabled.

See set_text_buffering.

Trait Implementations§

Source§

impl Debug for Parser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Parser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Parse for Parser

Source§

type Output = Event

The type of XML event which is emitted by the parser.
Source§

fn parse(&mut self, r: &mut &[u8], at_eof: bool) -> Result<Option<Self::Output>>

Parse a single event from the bytes in buf. Read more
Source§

fn release_temporaries(&mut self)

Release all temporary buffers or other ephemeral allocations Read more
Source§

fn parse_all<F: FnMut(Self::Output)>( &mut self, data: &mut &[u8], at_eof: bool, f: F, ) -> Result<()>

Parse all data from the given buffer and pass the generated events to a callback. Read more
Source§

fn parse_buf<T: Buf>( &mut self, buf: &mut T, at_eof: bool, ) -> Result<Option<Self::Output>>

Source§

fn parse_all_buf<T: Buf, F: FnMut(Self::Output)>( &mut self, buf: &mut T, at_eof: bool, f: F, ) -> Result<()>

Parse a bytes::Buf completely. Read more
Source§

impl WithOptions for Parser

Source§

fn with_options(options: Options) -> Self

Create a new instance using the given options.

Auto Trait Implementations§

§

impl Freeze for Parser

§

impl RefUnwindSafe for Parser

§

impl Send for Parser

§

impl Sync for Parser

§

impl Unpin for Parser

§

impl UnwindSafe for Parser

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.