Skip to main content

Namespace

Struct Namespace 

Source
#[repr(C)]
pub struct Namespace<'doc> { pub prefix: Option<&'doc str>, pub href: &'doc str, }
Expand description

A namespace binding (prefix → href). Lifetime-bound to the document’s arena.

prefix is None for the default namespace (xmlns="…").

§Layout

On the lean (default) build, prefix and href are &'doc str (fat slice). Under the c-abi feature this struct is byte-exact with libxml2’s _xmlNs as verified against libxml2 2.9.13 and 2.15.3. We do not claim layout compatibility with libxml2 versions we have not verified against; the t-upstream-layout c-test fails the build when the installed libxml2 header disagrees with the offsets here:

_xmlNs (64-bit), the odd duck among libxml2 structs because
`next` precedes `_private`:
  xmlNs         *next;            // offset  0   (chain pointer)
  xmlNsType      type;            // offset  8   (XML_LOCAL_NAMESPACE = 18)
  const xmlChar *href;            // offset 16
  const xmlChar *prefix;          // offset 24
  void          *_private;        // offset 32
  xmlDoc        *context;         // offset 40
  // sizeof == 48

We populate next via [DocumentBuilder::append_ns_def] so xmlSearchNs can walk the per-element ns_def chain. _private and context are zero-initialized; we don’t use them but the slots have to exist for ABI compatibility.

Fields§

§prefix: Option<&'doc str>§href: &'doc str

Implementations§

Source§

impl<'doc> Namespace<'doc>

Source

pub fn prefix(&self) -> Option<&'doc str>

Namespace prefix ("xlink", etc.), or None for the default namespace declaration (xmlns="...").

Prefer this method over direct ns.prefix field access. On the lean rlib build it just returns the field; on the c-abi build the storage type changes to a thin NUL-terminated ArenaCStr and this method handles the conversion.

Source

pub fn href(&self) -> &'doc str

Namespace URI (the right-hand side of xmlns="..."). Same rationale as prefix for preferring this over direct field access.

Trait Implementations§

Source§

impl<'doc> Debug for Namespace<'doc>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'doc> Freeze for Namespace<'doc>

§

impl<'doc> RefUnwindSafe for Namespace<'doc>

§

impl<'doc> Send for Namespace<'doc>

§

impl<'doc> Sync for Namespace<'doc>

§

impl<'doc> Unpin for Namespace<'doc>

§

impl<'doc> UnsafeUnpin for Namespace<'doc>

§

impl<'doc> UnwindSafe for Namespace<'doc>

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.