pub enum NodeEdge {
Start(Node),
End(Node),
}
Expand description
Node edges.
Used by Xot::traverse
and Xot::reverse_traverse
.
Variants§
Start(Node)
The start edge of a node. In case of an element this is the start tag. In case of document this is the start of the document.
End(Node)
The end edge of a node. In case of an element this is the end tag. In case of document this is the end of the document. For any other values, the end edge occurs immediately after the start edge.
Implementations§
Source§impl NodeEdge
impl NodeEdge
Sourcepub fn node(self) -> Node
pub fn node(self) -> Node
Returns the starting or ending node.
§Examples
let mut xot = xot::Xot::new();
let root = xot.parse("<p><a/><b><c/></b></p>").unwrap();
let p = xot.document_element(root).unwrap();
let a = xot.first_child(p).unwrap();
let b = xot.next_sibling(a).unwrap();
let c = xot.first_child(b).unwrap();
let traversed: Vec<xot::Node> = xot
.traverse(p)
.map(|edge| edge.node())
.collect();
assert_eq!(traversed, &[p, a, a, b, c, c, b, p]);
Sourcepub fn next(self, xot: &Xot) -> Option<Self>
pub fn next(self, xot: &Xot) -> Option<Self>
Returns the next edge in depth-first traversal order.
§Examples
let mut xot = xot::Xot::new();
let root = xot.parse("<p><a/><b><c/><d/><e/></b><f><g/><h/></f></p>").unwrap();
let traversed: Vec<xot::NodeEdge> = xot.traverse(root).collect();
let mut current = xot::NodeEdge::Start(root);
let mut traversed2 = vec![current];
while let Some(next) = current.next(&xot) {
if let xot::NodeEdge::End(node) = current {
// You can use `&mut Xot` inside the loop.
xot.remove(node);
}
traversed2.push(next);
current = next;
}
assert_eq!(traversed, traversed2);
Sourcepub fn previous(self, xot: &Xot) -> Option<Self>
pub fn previous(self, xot: &Xot) -> Option<Self>
Returns the previous edge in depth-first traversal order.
§Examples
let mut xot = xot::Xot::new();
let root = xot.parse("<p><a/><b><c/><d/><e/></b><f><g/><h/></f></p>").unwrap();
let rev_traversed: Vec<xot::NodeEdge> = xot.reverse_traverse(root).collect();
let mut current = xot::NodeEdge::End(root);
let mut rev_traversed2 = vec![current];
while let Some(next) = current.previous(&xot) {
if let xot::NodeEdge::Start(node) = current {
// You can use `&mut Xot` inside the loop.
xot.remove(node);
}
rev_traversed2.push(next);
current = next;
}
assert_eq!(rev_traversed, rev_traversed2);
Trait Implementations§
impl Copy for NodeEdge
impl Eq for NodeEdge
impl StructuralPartialEq for NodeEdge
Auto Trait Implementations§
impl Freeze for NodeEdge
impl RefUnwindSafe for NodeEdge
impl Send for NodeEdge
impl Sync for NodeEdge
impl Unpin for NodeEdge
impl UnwindSafe for NodeEdge
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more