Skip to main content

Attribute

Struct Attribute 

Source
#[repr(C)]
pub struct Attribute<'doc> { pub name: &'doc str, pub namespace: Cell<Option<&'doc Namespace<'doc>>>, pub value: &'doc str, pub next: Cell<Option<&'doc Attribute<'doc>>>, pub prev: Cell<Option<&'doc Attribute<'doc>>>, pub parent: Cell<Option<&'doc Node<'doc>>>, }
Expand description

An attribute on an element. Belongs to a doubly-linked list rooted at Node::first_attribute / Node::last_attribute on its owning element.

§Layout

libxml2’s _xmlAttr shares its first 8 fields with _xmlNode: generic walkers cast xmlAttr* to xmlNode* and read .type / .name. Under the c-abi feature this struct’s layout matches _xmlAttr byte-exact.

libxml2 _xmlAttr (64-bit):
  void           *_private;     // offset  0
  xmlElementType  type;         // offset  8   (XML_ATTRIBUTE_NODE = 2)
  const xmlChar  *name;         // offset 16
  xmlNode        *children;     // offset 24   (text/entity content nodes)
  xmlNode        *last;         // offset 32
  xmlNode        *parent;       // offset 40   (the element)
  xmlAttr        *next;         // offset 48
  xmlAttr        *prev;         // offset 56
  xmlDoc         *doc;          // offset 64
  xmlNs          *ns;           // offset 72
  xmlAttributeType atype;       // offset 80   (DTD type info)
  void           *psvi;         // offset 88
  ...

Fields§

§name: &'doc str§namespace: Cell<Option<&'doc Namespace<'doc>>>§value: &'doc str

Already entity-expanded by the parser.

§next: Cell<Option<&'doc Attribute<'doc>>>§prev: Cell<Option<&'doc Attribute<'doc>>>§parent: Cell<Option<&'doc Node<'doc>>>

Element this attribute belongs to. None only for a freshly-allocated attribute not yet attached via DocumentBuilder::append_attribute.

Implementations§

Source§

impl<'doc> Attribute<'doc>

Source

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

Attribute name (xlink:href, id, etc.).

Prefer this method over direct attr.name field access. The pub name field stays stable on the lean rlib build; in the c-abi build it becomes a thin NUL-terminated ArenaCStr. This method returns &str either way.

Source

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

The attribute’s local name (the part after any prefix:).

Layout-agnostic, mirroring Node::local_name: on the lean build name is the full QName, while on the c-abi build the prefix is stripped at parse time so name() is already local. Callers matching a namespaced attribute by its local part should use this rather than name().

Source

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

Attribute value (entity-expanded by the parser). Same rationale as name for preferring this over direct field access.

In the c-abi build, attribute values are stored two ways: the sup-xml-only value slot (set by our parser / new_attribute API) and the libxml2-standard text-node chain rooted at children (the path libxslt writes to when it builds attributes during an XSLT transform — it doesn’t know about our tail field). When value is empty, fall back to walking children so attributes built post-parse by libxslt still report the right text.

Trait Implementations§

Source§

impl Debug for Attribute<'_>

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 Attribute<'doc>

§

impl<'doc> !RefUnwindSafe for Attribute<'doc>

§

impl<'doc> !Send for Attribute<'doc>

§

impl<'doc> !Sync for Attribute<'doc>

§

impl<'doc> !UnwindSafe for Attribute<'doc>

§

impl<'doc> Unpin for Attribute<'doc>

§

impl<'doc> UnsafeUnpin for Attribute<'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.