NamespaceStack

Struct NamespaceStack 

Source
pub struct NamespaceStack<'ns> { /* private fields */ }
Expand description

A NamespaceStack is a use of a Namespace structure within a document; in general they form a pair, with the Namespace created first and a NamespaceStack following.

The stack consists of frames, which can be pushed and popped. Within a frame there are mappings between prefix strings and URI strings; there will be at most one mapping for each prefix within the frame. Different stack frames may map the same prefix differently, though.

A mapping for a prefix string is determined by finding that mapping in the topmost stack frame if possible; if there is no mapping in that frame, the next frame down is examined, and so on.

URI and prefix strings are stored within the Namespace structure, and are referred to by ’id’s in most of the API - as are mappings from prefix to URI.

A client of the NamespaceStack should add mappings to the NamespaceStack with a [NamespaceStack::add] operation, which returns an NSMap; it can look up mappings for a prefix string by resolving the prefix string to an ID with [NamespaceStack::find_prefix], and then finding the map using NamespaceStack::find_mapping.

A client can iterate through all the mappings using the iter() method.

§Example

use hml_rs::names::{NamespaceStack, Namespace};

let mut ns  = Namespace::new(true);
let mut nst = NamespaceStack::new(&mut ns);

Implementations§

Source§

impl<'ns> NamespaceStack<'ns>

Source

pub fn new(namespaces: &'ns mut Namespace) -> Self

Create a new NamespaceStack, mutably borrowing the Namespace for its lifetime

Source

pub fn uses_xmlns(&self) -> bool

Return true if the Namespace was specified to use the XML namespace (at creation)

Source

pub fn add_null_ns(&mut self)

Add the null namespace

This is normally done at the creation of a NamespaceStack

Source

pub fn add_default_xmls(&mut self)

Add the default XML namespaces to the stack frame

This is normally done at the creation of a NamespaceStack

Source

pub fn push_frame(&mut self)

Push a new stack frame on to the NamespaceStack

Source

pub fn pop_frame(&mut self)

Pop the topmost stack frame from the NamespaceStack

Panics if the stack is empty

Source

pub fn add_mapping_by_id(&mut self, map: NSMap)

Add a mapping of NSPrefixId -> NSUriId to the topmost stack frame

Source

pub fn add_mapping_by_id_if_unset(&mut self, map: NSMap) -> bool

Add a mapping if it does not exist in the topmost stack fram

Source

pub fn find_mapping(&self, prefix_id: NSPrefixId) -> Option<NSUriId>

Find a mapping of an NSPrefixId at the highest level of the stack that it exists

Returns None if there is no mapping on the stack at all

Source

pub fn find_prefix_id(&mut self, prefix: &str) -> Option<NSPrefixId>

Find the NSPrefixId corresponding to a string within the underlying Namespace

Source

pub fn iter_top_mappings(&self) -> NamespaceStackFrameIter<'_>

Get a slice of the mappings of the topmost frame

Source

pub fn borrow_mapping(&self, map: NSMap) -> (&str, &str)

Borrow the two strings corresponding to an NSMap within the Namespace

Source

pub fn name_str(&self, name: NSNameId) -> &str

Borrow the name corresponding to an NSNameId within the Namespace

Source

pub fn prefix_str(&self, prefix: NSPrefixId) -> &str

Borrow the prefix corresponding to an NSPrefixId within the Namespace

Source

pub fn uri_str(&self, uri: NSUriId) -> &str

Borrow the URI corresponding to an NSUriId within the Namespace

Source

pub fn add_name(&mut self, name: &str) -> NSNameId

Add a name for a string to the Namespace; if it is already in the Namespace then it is not added but the current NSNameId is used.

Source

pub fn add_ns(&mut self, prefix: &str, uri: &str) -> NSMap

Add a prefix -> URI mapping to the Namespace

Source

pub fn add_ns_if_unset(&mut self, prefix: &str, uri: &str) -> (NSMap, bool)

Add a prefix -> URI mapping to the Namespace

Source

pub fn fmt_map<W: Write>(&self, w: &mut W, map: NSMap) -> Result<(), Error>

Format an NSMap within the Namespace

Trait Implementations§

Source§

impl<'ns, 'b> IntoIterator for &'b NamespaceStack<'ns>

Source§

type Item = NSMap

The type of the elements being iterated over.
Source§

type IntoIter = NamespaceStackIterator<'ns, 'b>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'ns> Freeze for NamespaceStack<'ns>

§

impl<'ns> RefUnwindSafe for NamespaceStack<'ns>

§

impl<'ns> Send for NamespaceStack<'ns>

§

impl<'ns> Sync for NamespaceStack<'ns>

§

impl<'ns> Unpin for NamespaceStack<'ns>

§

impl<'ns> !UnwindSafe for NamespaceStack<'ns>

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.