Skip to main content

AstBuilder

Struct AstBuilder 

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

An incremental consumer that pulls events directly into an arena.

Implementations§

Source§

impl AstBuilder

Source

pub fn new() -> Self

Create an empty builder. It does not borrow or own the parser’s source.

Source

pub fn with_capacity(nodes: usize, depth: usize) -> Self

Reserve arena and open-container capacity for allocation reuse.

Source

pub fn consume<'a>( &mut self, events: &mut impl Iterator<Item = Result<Event<'a>, StreamError>>, budget: usize, ) -> Result<BuildProgress, StreamError>

Pull up to budget events, retaining construction state between calls. A zero budget does no work. Reaching the exact budget does not probe the iterator for another event.

§Errors

Returns parser errors or StreamError::Unbalanced for malformed streams. A failed builder cannot be finished.

Source

pub fn finish<S: AsRef<str>>( self, source: S, ) -> Result<Document<S>, StreamError>

Attach the original source after the stream has ended. The buffer is moved, not copied.

§Errors

Returns StreamError::Unbalanced if consumption failed or has not reached EOF, or StreamError::InvalidRange for invalid source-backed values.

Source

pub fn len(&self) -> usize

Number of nodes constructed so far; useful when selecting the next work budget.

Source

pub fn is_empty(&self) -> bool

Whether no nodes have been constructed.

Trait Implementations§

Source§

impl Debug for AstBuilder

Source§

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

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

impl Default for AstBuilder

Source§

fn default() -> Self

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

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.