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, ResolvedEvent, XmlVersion};
use std::io;
let doc = b"<?xml version='1.0'?><hello>World!</hello>";
let mut fp = Parser::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(), ResolvedEvent::XmlDeclaration(_, XmlVersion::V1_0)));In contrast to a RawParser, the Parser enforces well-formedness and
namespace-well-formedness.
Implementations§
Trait Implementations§
source§impl Parse for Parser
impl Parse for Parser
§type Output = ResolvedEvent
type Output = ResolvedEvent
The type of XML event which is emitted by the parser.
source§fn parse<T: Buf>(
&mut self,
r: &mut T,
at_eof: bool,
) -> Result<Option<Self::Output>>
fn parse<T: Buf>( &mut self, r: &mut T, at_eof: bool, ) -> Result<Option<Self::Output>>
Parse a single event from the bytes in
buf. Read moresource§fn release_temporaries(&mut self)
fn release_temporaries(&mut self)
Release all temporary buffers or other ephemeral allocations Read more
source§impl WithOptions for Parser
impl WithOptions for Parser
source§fn with_options(options: Options) -> Self
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> WithContext for Twhere
T: WithOptions,
impl<T> WithContext for Twhere
T: WithOptions,
source§fn with_context(ctx: Arc<Context>) -> T
fn with_context(ctx: Arc<Context>) -> T
👎Deprecated since 0.10.0: use WithOptions::with_options
Create an object with the given parsing context.