Struct oop_inheritance::Node
source · pub struct Node { /* private fields */ }
Expand description
Represents an node as a type managed by reference-counting.
Implementations§
source§impl Node
impl Node
pub fn new() -> Node
sourcepub fn downgrade_ref(&self) -> WeakNodeRef
pub fn downgrade_ref(&self) -> WeakNodeRef
Downgrades the node reference into a weak reference.
sourcepub fn set<T>(&self, value: T) -> Self
pub fn set<T>(&self, value: T) -> Self
Overrides a component of the node. This method is chainable.
sourcepub fn delete<T>(&self) -> bool
pub fn delete<T>(&self) -> bool
Deletes a component of the node.
Returns true
if any component was deleted;
otherwise returns false
.
pub fn parent(&self) -> Option<Node>
pub fn children(&self) -> Vec<Node>
pub fn child_at(&self, index: usize) -> Option<Node>
sourcepub fn num_children(&self) -> usize
pub fn num_children(&self) -> usize
Returns the number of children.
sourcepub fn add_child(&self, child: impl AsRef<Node>)
pub fn add_child(&self, child: impl AsRef<Node>)
Adds a child node to the end of the children collection.
If child
is already child of an node, it is removed and then added
as part of this node.
sourcepub fn add_child_at(&self, index: usize, child: impl AsRef<Node>)
pub fn add_child_at(&self, index: usize, child: impl AsRef<Node>)
Adds a child node at the index index
of the children collection.
If child
is already child of an node, it is removed and then added
as part of this node.
Panics
This method panics if index
is out of bounds.
sourcepub fn add_children(&self, children: impl IntoIterator<Item = impl AsRef<Node>>)
pub fn add_children(&self, children: impl IntoIterator<Item = impl AsRef<Node>>)
Adds a sequence of children to the end of the children collection.
This is equivalent to iterating the sequence and invoking add_child()
with every child.
sourcepub fn swap_children_by_indices(&self, child_1: usize, child_2: usize)
pub fn swap_children_by_indices(&self, child_1: usize, child_2: usize)
sourcepub fn remove_child(&self, child: impl AsRef<Node>) -> bool
pub fn remove_child(&self, child: impl AsRef<Node>) -> bool
Removes a child. Returns true
if the child has been removed, or false
otherwise.
sourcepub fn remove_children(&self)
pub fn remove_children(&self)
Removes all children nodes from the node.
sourcepub fn remove_from_parent(&self) -> bool
pub fn remove_from_parent(&self) -> bool
Removes the node from its parent. Returns true
if the child has been removed, or false
otherwise.
sourcepub fn resolve_path(&self, path: &str) -> Option<Node>
pub fn resolve_path(&self, path: &str) -> Option<Node>
Resolves an Node path. An Node path is resolved as follows:
- Let segments be the splitting of the path by the slash character (
/
). - Let r be the initial node.
- For every segment s:
- If
s == ".first"
, let r be the first child of r or otherwiseNone
. - If
s == ".last"
, let r be the last child of r or otherwiseNone
. - If
s == ".."
, let r be the parent of r or otherwiseNone
. - If s is non-empty, let r be a child of r such that
child.name() == s
or otherwiseNone
.
- If
- Return r
sourcepub fn is<T: TryFrom<Self, Error = ClassError>>(&self) -> bool
pub fn is<T: TryFrom<Self, Error = ClassError>>(&self) -> bool
Indicates whether an Node is of a certain Node subtype.
sourcepub fn to<T: TryFrom<Self, Error = ClassError>>(&self) -> Result<T, ClassError>
pub fn to<T: TryFrom<Self, Error = ClassError>>(&self) -> Result<T, ClassError>
Attempts to convert this Node reference into a T
reference.