Skip to main content

RtfBuilder

Struct RtfBuilder 

Source
pub struct RtfBuilder {
    pub typed_nodes: Vec<(NodeId, Box<(String, String)>)>,
    /* private fields */
}
Expand description

Helper for populating an RtfIndex one node at a time. The builder owns the slot index it’ll be pushed into so it can encode child / parent / attribute ids directly to global form during construction; no second pass needed.

Typical usage from the XSLT engine:

let mut b = idx.start_rtf();
let root = b.add_document();
let elem = b.add_element(root, "foo", "", None, &[]);
b.add_text(elem, "hello");
let root_id = idx.finish_rtf(b);   // returns encoded root NodeId

Fields§

§typed_nodes: Vec<(NodeId, Box<(String, String)>)>

Schema-aware: (encoded NodeId, (type-ns, type-local)) for each constructed node carrying a type= / xsl:type= annotation. Collected during construction (the builder already encodes ids to global form) and drained into the host index’s PSVI table by DocIndex::finish_rtf.

Implementations§

Source§

impl RtfBuilder

Source

pub fn add_document(&mut self) -> NodeId

Add the synthetic Document node. Must be the first call — the index conventionally treats local id 0 as the document root. Returns the encoded global id.

Source

pub fn add_element( &mut self, parent: NodeId, qname: &str, namespace_uri: &str, prefix: Option<&str>, ) -> NodeId

Add an element child of parent. parent is a global id (the value previously returned by add_document or another add_element).

Source

pub fn add_text(&mut self, parent: NodeId, content: &str) -> NodeId

Source

pub fn add_comment(&mut self, parent: NodeId, content: &str) -> NodeId

Source

pub fn add_pi(&mut self, parent: NodeId, target: &str, data: &str) -> NodeId

Source

pub fn start_attrs(&mut self, elem_global: NodeId)

Set the contiguous attribute-id range for an element. Attributes are appended via add_attribute AFTER the element and BEFORE any further content children — caller is responsible for ordering and for calling finish_attrs to lock in the range.

Source

pub fn add_attribute( &mut self, elem_global: NodeId, qname: &str, namespace_uri: &str, prefix: Option<&str>, value: &str, ) -> NodeId

Source

pub fn start_ns(&mut self, elem_global: NodeId)

Open the namespace-node range for elem_global. Subsequent [add_namespace_node] calls populate the contiguous slab; the range covers them automatically. Callers must invoke this after the attribute slab (start_attrs / add_attribute) and before the first child, so attribute and namespace nodes don’t interleave with element children.

Source

pub fn add_namespace_node( &mut self, elem_global: NodeId, prefix: Option<&str>, uri: &str, ) -> NodeId

Add an in-scope namespace node to elem_global. prefix is None for the default-namespace binding and Some("") is treated identically; otherwise pass the prefix without colons. Returns the globally-encoded id of the new namespace node so callers can index it directly (rarely needed — the typical access path is ns_range(elem)).

Source

pub fn build(self) -> RtfIndex

Consume the builder into the populated RtfIndex.

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> Same for T

Source§

type Output = T

Should always be Self
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.