Skip to main content

AbxParser

Struct AbxParser 

Source
pub struct AbxParser<'a> { /* private fields */ }
Expand description

Zero-allocation pull parser that works on an in-memory &[u8].

Advance through the document with next_event or use one of the higher-level helpers.

Implementations§

Source§

impl<'a> AbxParser<'a>

Source

pub fn new(input: &'a [u8]) -> Result<Self>

Create a parser, validating the 4-byte magic header.

Source

pub fn is_empty(&self) -> bool

true when no more bytes remain.

Source

pub fn next_event(&mut self) -> Result<Option<Event>>

Pull the next Event. Returns None at end of input.

Source

pub fn collect_events(&mut self) -> Result<Vec<Event>>

Drain all remaining events into a Vec.

Source

pub fn find_attribute( &mut self, element: &str, attr: &str, ) -> Result<Option<AttributeValue>>

Return the value of the first matching attr_name inside any <element_name> in the remaining stream. Ok(None) means the element/attribute wasn’t found before the document ended; Err means a parse failure interrupted the search. Callers that don’t care about that distinction can collapse both into None with .ok().flatten().

Source

pub fn find_all_attributes( &mut self, element: &str, attr: &str, ) -> Result<Vec<AttributeValue>>

All values of attr_name found in <element_name> tags.

Source

pub fn attributes_of(&mut self, element: &str) -> Result<Option<Vec<Attribute>>>

Attributes of the first <element_name> tag. Ok(None) means no matching tag was found before the document ended; Err means a parse failure interrupted the search — see find_attribute for how to collapse both into a plain None.

Source

pub fn all_attributes_of( &mut self, element: &str, ) -> Result<Vec<Vec<Attribute>>>

Attributes of every <element_name> tag.

Source

pub fn to_xml(&mut self) -> Result<String>

Render the rest of the document as an XML string.

Source

pub fn write_xml(&mut self, writer: &mut impl Write) -> Result<()>

Write the rest of the document as XML into any std::io::Write sink.

More memory-efficient than to_xml for very large documents because it does not accumulate the whole result in a String.

Source

pub fn deserialize_next<T: DeserializeOwned>( &mut self, element: &str, ) -> Result<Option<T>>

Find the next <element>, deserialize its attributes (and direct text content, via a #[serde(rename = "$text")] field) into T, then skip past its matching end tag. Ok(None) at end of document.

Source

pub fn deserialize_all<T: DeserializeOwned>( &mut self, element: &str, ) -> Result<Vec<T>>

Deserialize every remaining <element> into a Vec<T>.

Source

pub fn into_map(self) -> Result<HashMap<String, Vec<HashMap<String, String>>>>

Collect the whole document into a HashMap<element → Vec<HashMap<attr → value_str>>>.

Trait Implementations§

Source§

impl<'a> Debug for AbxParser<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for AbxParser<'a>

§

impl<'a> RefUnwindSafe for AbxParser<'a>

§

impl<'a> Send for AbxParser<'a>

§

impl<'a> Sync for AbxParser<'a>

§

impl<'a> Unpin for AbxParser<'a>

§

impl<'a> UnsafeUnpin for AbxParser<'a>

§

impl<'a> UnwindSafe for AbxParser<'a>

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.