pub trait Node<'a>:
Copy
+ Eq
+ 'a {
// Required methods
fn kind(self) -> NodeKind;
fn parent(self) -> Option<Self>;
fn children(self) -> impl Iterator<Item = Self> + 'a;
fn attributes(self) -> impl Iterator<Item = Self> + 'a;
fn namespaces(self) -> impl Iterator<Item = Self> + 'a;
fn expanded_name(self) -> Option<ExpandedName>;
fn string_value(self) -> String;
fn document_order(self, other: Self) -> Ordering;
// Provided method
fn is_id_attribute(self) -> bool { ... }
}Expand description
A node in the caller’s tree, viewed as an XPath 1.0 data-model node.
Copy because axis iterators (axes.rs) produce many short-lived
handles — modeled after roxmltree::Node<'a>, not a NodeId/arena
scheme.
Methods take self by value (not &self) despite the Copy bound —
deliberately, so the returned impl Iterator<Item = Self> + 'a only
captures 'a and not an additional borrow of a locally-owned handle
(Rust’s return-position-impl-trait-in-traits rules otherwise implicitly
capture the &self lifetime too, which conflicts with callers that
build axis iterators from an owned, short-lived N).
Required Methods§
Sourcefn parent(self) -> Option<Self>
fn parent(self) -> Option<Self>
The node’s parent, if any. Root nodes have no parent. Attribute and
namespace nodes have a parent (their owner element) despite not
being among that element’s children().
Sourcefn children(self) -> impl Iterator<Item = Self> + 'a
fn children(self) -> impl Iterator<Item = Self> + 'a
The node’s children. Non-empty only for Root/Element (§5.1/§5.2)
— attribute and namespace nodes are never children of anything.
Sourcefn attributes(self) -> impl Iterator<Item = Self> + 'a
fn attributes(self) -> impl Iterator<Item = Self> + 'a
The element’s attribute nodes. Non-empty only for Element (§5.3).
Not part of children() — see the document-order rule below.
Sourcefn namespaces(self) -> impl Iterator<Item = Self> + 'a
fn namespaces(self) -> impl Iterator<Item = Self> + 'a
The element’s namespace nodes. Non-empty only for Element (§5.4).
Not part of children().
Sourcefn expanded_name(self) -> Option<ExpandedName>
fn expanded_name(self) -> Option<ExpandedName>
The node’s expanded name. None for Root/Comment/Text, which
have no name; Some for Element/Attribute/Namespace/
ProcessingInstruction per the §5 table.
Sourcefn string_value(self) -> String
fn string_value(self) -> String
The node’s string-value, computed per node kind per the §5 table (e.g. Element/Root: concatenation of the string-values of all descendant text nodes, in document order).
Sourcefn document_order(self, other: Self) -> Ordering
fn document_order(self, other: Self) -> Ordering
Total order per document order (§5): an element occurs before its
namespace nodes, which occur before its attribute nodes, which
occur before its children, each subtree recursively in document
order. (Relative order among an element’s own namespace nodes, and
among its own attribute nodes, is implementation-defined — it only
needs to be some stable order.) Must be consistent with
children()/attributes()/namespaces().
Provided Methods§
Sourcefn is_id_attribute(self) -> bool
fn is_id_attribute(self) -> bool
Whether this attribute node is of type ID (§5.3, §4.1’s id()) —
i.e. whether XPath’s id() function should be able to find this
attribute’s owner element by this attribute’s string-value. The
XPath 1.0 data model derives this from a DTD or schema; most callers
have no such information, so the default is false everywhere
(id() then always returns an empty node-set, never an error — the
function itself is always implemented). Callers that do have ID
information (DTD validation, xml:id, a known convention) should
override this on their Attribute-kind nodes. Meaningless (and
never called by this crate) on non-Attribute nodes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".