Skip to main content

Element

Struct Element 

Source
pub struct Element<'d> { /* private fields */ }
Expand description

A borrowed handle to one element, carrying the arena it came from.

This is the type the semantic pass works with. It is Copy and two words wide, so navigation (child, children, attr) is free of allocation and of lifetime noise.

Implementations§

Source§

impl<'d> Element<'d>

Source

pub fn tag(self) -> Tag

This element’s tag.

Source

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

This element’s local name as written in the document.

Source

pub fn parent(self) -> Option<Element<'d>>

The parent element, or None at the root.

Source

pub fn children(self) -> Children<'d> ⓘ

Direct children, in document order.

Source

pub fn children_with(self, tag: Tag) -> impl Iterator<Item = Element<'d>>

Direct children with the given tag.

Source

pub fn child(self, tag: Tag) -> Option<Element<'d>>

The first direct child with the given tag.

Source

pub fn descendant(self, tag: Tag) -> Option<Element<'d>>

The first descendant with the given tag, searched depth-first.

Mirrors the reference implementation’s element.find(".//Tag"), which is how it locates a data encoding anywhere under a parameter type.

Source

pub fn descendant_any(self, tags: &[Tag]) -> Option<Element<'d>>

The first descendant matching any of tags, searched depth-first, preferring the shallowest match and then document order.

Source

pub fn attr(self, key: AttrKey) -> Option<&'d str>

An attribute value by well-known key.

Source

pub fn attr_named(self, name: &str) -> Option<&'d str>

An attribute value by literal name, for attributes outside AttrKey.

Source

pub fn attr_names(self) -> impl Iterator<Item = &'d str>

Attribute names present on this element, in document order.

Source

pub fn text(self) -> Option<&'d str>

Text content, if this element has any and no element children.

Source

pub fn path(self) -> String

The /-joined element path from the root to this element, for diagnostics.

Trait Implementations§

Source§

impl<'d> Clone for Element<'d>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'d> Copy for Element<'d>

Auto Trait Implementations§

§

impl<'d> Forget for Element<'d>

§

impl<'d> Freeze for Element<'d>

§

impl<'d> Move for Element<'d>

§

impl<'d> RefUnwindSafe for Element<'d>

§

impl<'d> Send for Element<'d>

§

impl<'d> Sync for Element<'d>

§

impl<'d> Unpin for Element<'d>

§

impl<'d> UnsafeUnpin for Element<'d>

§

impl<'d> UnwindSafe for Element<'d>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.