Struct rxml::RawParser

source ·
pub struct RawParser { /* private fields */ }
Expand description

§Low-level restricted XML 1.0 parser (without namespace support)

This parser emits RawEvent items, which represent the logical structure of the XML document before resolution of namespaces. If you want to use namespaces and have them resolved fully, use Parser instead.

§Caveats

It is possible for an XML document to pass parsing using just this parser and still be not well-formed or namespace-well-formed. In particular, the following cases are not detected and must be handled by consumer code:

  • Duplicate attributes
  • Uses of undeclared prefixes
  • Multiple attributes resolving to the same namespace URI / localpart pair after prefix expansion

See Parser for a full parser implementation which ensures well-formedness and namespace-well-formedness.

§Example

use rxml::{RawParser, Parse, Error, RawEvent, XmlVersion};
use std::io;
let doc = b"<?xml version='1.0'?><hello>World!</hello>";
let mut fp = RawParser::new();
// We expect a WouldBlock, because the XML declaration is not complete yet
assert!(matches!(
	fp.parse(&mut &doc[..10], false).err().unwrap(),
	Error::IO(e) if e.kind() == io::ErrorKind::WouldBlock
));

// 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(), RawEvent::XmlDeclaration(_, XmlVersion::V1_0)));

Implementations§

source§

impl RawParser

source

pub fn new() -> Self

Create a new parser

Trait Implementations§

source§

impl Debug for RawParser

source§

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

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

impl Default for RawParser

source§

fn default() -> Self

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

impl Parse for RawParser

§

type Output = RawEvent

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 RawParser

source§

fn with_options(options: Options) -> Self

Create a new instance using the given options.

Auto Trait Implementations§

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>,

§

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>,

§

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.
source§

impl<T> WithContext for T
where T: WithOptions,

source§

fn with_context(ctx: Arc<Context>) -> T

👎Deprecated since 0.10.0: use WithOptions::with_options
Create an object with the given parsing context.