pub trait TrackNamespace {
// Required methods
fn declare_fixed(
&mut self,
prefix: Option<&NcNameStr>,
name: Namespace,
) -> bool;
fn declare_auto(&mut self, name: Namespace) -> (bool, Option<&NcNameStr>);
fn declare_with_auto_prefix(
&mut self,
name: Namespace,
) -> (bool, &NcNameStr);
fn get_prefix_or_default(
&self,
name: Namespace,
) -> Result<Option<&NcNameStr>, PrefixError>;
fn get_prefix(&self, name: Namespace) -> Result<&NcNameStr, PrefixError>;
fn push(&mut self);
fn pop(&mut self);
fn new_default_declaration(&self) -> Option<&Namespace>;
fn new_prefix_declarations(
&self,
) -> Box<dyn Iterator<Item = (&Namespace, &NcNameStr)> + '_>;
}Expand description
Trait for a thing tracking namespace declarations.
Indirection via this trait allows to have different paradigms for declaring and managing namespace prefixes.
Objects implementing this trait expect the following protocol:
- Declare all namespace URIs introduced on an element using
declareanddeclare_auto. - Commit to the element using
push - Process all child elements by recursion
- Call
popto end the element.
Asymmetric calls to push/pop may cause panics or memory leaks.
Required Methods§
Sourcefn declare_fixed(&mut self, prefix: Option<&NcNameStr>, name: Namespace) -> bool
fn declare_fixed(&mut self, prefix: Option<&NcNameStr>, name: Namespace) -> bool
Declare a namespace URI with a defined prefix.
Note: There is no guarantee that the given prefix will be returned
from calls to get_prefix or get_prefix_or_default after the next
call to push.
Returns whether the prefix is freshly declared.
§Panics
Calling this twice between two calls to push with the same prefix
is a programming error and causes a panic.
Sourcefn declare_auto(&mut self, name: Namespace) -> (bool, Option<&NcNameStr>)
fn declare_auto(&mut self, name: Namespace) -> (bool, Option<&NcNameStr>)
Declare a namespace URI with an auto-generated prefix or by using the default namespace.
Note: There is no guarantee that the returned prefix will be
returned from calls to get_prefix_or_default after the next call to
push.
Returns whether the prefix is freshly declared and the resulting prefix (or None, if prefixless).
This may return a non-auto-generated prefix if the namespace URI is already declared on this or a parent element.
Sourcefn declare_with_auto_prefix(&mut self, name: Namespace) -> (bool, &NcNameStr)
fn declare_with_auto_prefix(&mut self, name: Namespace) -> (bool, &NcNameStr)
Declare a namespace URI with an auto-generated prefix.
Note: There is no guarantee that the returned prefix will be
returned from calls to get_prefix or get_prefix_or_default after
the next call to push.
Returns whether the prefix is freshly declared and the resulting prefix.
This may return a non-auto-generated prefix if the namespace URI is already declared on this or a parent element. If the URI is already used for the default namespace, this function will nontheless return a prefix.
Sourcefn get_prefix_or_default(
&self,
name: Namespace,
) -> Result<Option<&NcNameStr>, PrefixError>
fn get_prefix_or_default( &self, name: Namespace, ) -> Result<Option<&NcNameStr>, PrefixError>
Get the prefix for a given URI, which may be empty if the namespace with that URI is defined as the default namespace.
Sourcefn get_prefix(&self, name: Namespace) -> Result<&NcNameStr, PrefixError>
fn get_prefix(&self, name: Namespace) -> Result<&NcNameStr, PrefixError>
Get the prefix for a given URI.
This returns an error if the given URI is declared as default namespace and there is no matching prefix.
Sourcefn new_default_declaration(&self) -> Option<&Namespace>
fn new_default_declaration(&self) -> Option<&Namespace>
Return the newly declared default namespace, if any.
This returns None if and only if no default namespace has been
declared yet for the upcoming element.
Note: In the root element, None will be returned even if the
default namespace has been explicitly set to the empty namespace name,
as that is the default.