Skip to main content

TreeBuilder

Struct TreeBuilder 

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

Builds a Document from events, in document order.

Adjacent text is merged into one text node and empty text is dropped, as the XDM requires. Attributes must come right after their element’s start, before its content; an attribute whose expanded name is already on the element replaces it.

Implementations§

Source§

impl TreeBuilder

Source

pub fn new() -> Self

A builder holding only the document node.

Source

pub fn start_element(&mut self, name: QName) -> Result<(), DocumentError>

Opens an element.

§Errors

A document too large for the arena.

Source

pub fn attribute( &mut self, name: QName, value: &str, ) -> Result<(), DocumentError>

Adds an attribute to the element just opened.

§Errors

No element is open, or the element already has content.

Source

pub fn text(&mut self, value: &str) -> Result<(), DocumentError>

Adds text, merged with text added just before.

§Errors

A document too large for the arena.

Source

pub fn comment(&mut self, value: &str) -> Result<(), DocumentError>

Adds a comment.

§Errors

A document too large for the arena.

Source

pub fn processing_instruction( &mut self, target: &str, value: &str, ) -> Result<(), DocumentError>

Adds a processing instruction.

§Errors

A document too large for the arena.

Source

pub fn end_element(&mut self) -> Result<(), DocumentError>

Closes the innermost open element.

§Errors

No element is open.

Source

pub fn finish( self, document_uri: Option<String>, base_uri: Option<String>, ) -> Result<Rc<Document>, DocumentError>

The finished document, with its document URI and the base URI of its nodes.

§Errors

An element is still open.

Trait Implementations§

Source§

impl Debug for TreeBuilder

Source§

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

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

impl Default for TreeBuilder

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.