Struct xml::namespace::NamespaceStack
source · pub struct NamespaceStack(pub Vec<Namespace>);
Expand description
Namespace stack is a sequence of namespaces.
Namespace stack is used to represent cumulative namespace consisting of combined namespaces from nested elements.
Tuple Fields§
§0: Vec<Namespace>
Implementations§
source§impl NamespaceStack
impl NamespaceStack
sourcepub fn empty() -> NamespaceStack
pub fn empty() -> NamespaceStack
Returns an empty namespace stack.
sourcepub fn default() -> NamespaceStack
pub fn default() -> NamespaceStack
Returns a namespace stack with default items in it.
Default items are the following:
xml
→http://www.w3.org/XML/1998/namespace
;xmlns
→http://www.w3.org/2000/xmlns/
.
sourcepub fn push_empty(&mut self) -> &mut NamespaceStack
pub fn push_empty(&mut self) -> &mut NamespaceStack
Adds an empty namespace to the top of this stack.
sourcepub fn pop(&mut self) -> Namespace
pub fn pop(&mut self) -> Namespace
Removes the topmost namespace in this stack.
Panics if the stack is empty.
sourcepub fn try_pop(&mut self) -> Option<Namespace>
pub fn try_pop(&mut self) -> Option<Namespace>
Removes the topmost namespace in this stack.
Returns Some(namespace)
if this stack is not empty and None
otherwise.
sourcepub fn peek_mut(&mut self) -> &mut Namespace
pub fn peek_mut(&mut self) -> &mut Namespace
Borrows the topmost namespace mutably, leaving the stack intact.
Panics if the stack is empty.
sourcepub fn peek(&self) -> &Namespace
pub fn peek(&self) -> &Namespace
Borrows the topmost namespace immutably, leaving the stack intact.
Panics if the stack is empty.
sourcepub fn put_checked<P, U>(&mut self, prefix: P, uri: U) -> boolwhere
P: Into<String> + AsRef<str>,
U: Into<String> + AsRef<str>,
pub fn put_checked<P, U>(&mut self, prefix: P, uri: U) -> boolwhere P: Into<String> + AsRef<str>, U: Into<String> + AsRef<str>,
Puts a mapping into the topmost namespace if this stack does not already contain one.
Returns a boolean flag indicating whether the insertion has completed successfully. Note that both key and value are matched and the mapping is inserted if either namespace prefix is not already mapped, or if it is mapped, but to a different URI.
Parameters
prefix
— namespace prefix;uri
— namespace URI.
Return value
true
if prefix
has been inserted successfully; false
if the prefix
was already present in the namespace stack.
sourcepub fn put<P, U>(&mut self, prefix: P, uri: U) -> boolwhere
P: Into<String>,
U: Into<String>,
pub fn put<P, U>(&mut self, prefix: P, uri: U) -> boolwhere P: Into<String>, U: Into<String>,
Puts a mapping into the topmost namespace in this stack.
This method does not override a mapping in the topmost namespace if it is already present, however, it does not depend on other namespaces in the stack, so it is possible to put a mapping which is present in lower namespaces.
Returns a boolean flag indicating whether the insertion has completed successfully.
Parameters
prefix
— namespace prefix;uri
— namespace URI.
Return value
true
if prefix
has been inserted successfully; false
if the prefix
was already present in the namespace.
sourcepub fn get<'a, P: ?Sized + AsRef<str>>(&'a self, prefix: &P) -> Option<&'a str>
pub fn get<'a, P: ?Sized + AsRef<str>>(&'a self, prefix: &P) -> Option<&'a str>
Performs a search for the given prefix in the whole stack.
This method walks the stack from top to bottom, querying each namespace
in order for the given prefix. If none of the namespaces contains the prefix,
None
is returned.
Parameters
prefix
— namespace prefix.
sourcepub fn squash(&self) -> Namespace
pub fn squash(&self) -> Namespace
Combines this stack of namespaces into a single namespace.
Namespaces are combined in left-to-right order, that is, rightmost namespace elements take priority over leftmost ones.
sourcepub fn checked_target(&mut self) -> CheckedTarget<'_>
pub fn checked_target(&mut self) -> CheckedTarget<'_>
Returns an object which implements Extend
using put_checked()
instead of put()
.
See CheckedTarget
for more information.
sourcepub fn iter(&self) -> NamespaceStackMappings<'_> ⓘ
pub fn iter(&self) -> NamespaceStackMappings<'_> ⓘ
Returns an iterator over all mappings in this namespace stack.
Trait Implementations§
source§impl Clone for NamespaceStack
impl Clone for NamespaceStack
source§fn clone(&self) -> NamespaceStack
fn clone(&self) -> NamespaceStack
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for NamespaceStack
impl Debug for NamespaceStack
source§impl<'a> Extend<(&'a str, &'a str)> for NamespaceStack
impl<'a> Extend<(&'a str, &'a str)> for NamespaceStack
source§fn extend<T>(&mut self, iterable: T)where
T: IntoIterator<Item = UriMapping<'a>>,
fn extend<T>(&mut self, iterable: T)where T: IntoIterator<Item = UriMapping<'a>>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<'a> IntoIterator for &'a NamespaceStack
impl<'a> IntoIterator for &'a NamespaceStack
source§impl PartialEq<NamespaceStack> for NamespaceStack
impl PartialEq<NamespaceStack> for NamespaceStack
source§fn eq(&self, other: &NamespaceStack) -> bool
fn eq(&self, other: &NamespaceStack) -> bool
self
and other
values to be equal, and is used
by ==
.