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

source

pub fn new() -> Node

source

pub fn downgrade_ref(&self) -> WeakNodeRef

Downgrades the node reference into a weak reference.

source

pub fn has<T>(&self) -> bool
where T: Any + Send + Sync,

Checks whether node has a specified component.

source

pub fn get<T>(&self) -> Option<Arc<T>>
where T: Any + Send + Sync,

Retrieves a component from the node.

source

pub fn set<T>(&self, value: T) -> Self
where T: Any + Send + Sync,

Overrides a component of the node. This method is chainable.

source

pub fn delete<T>(&self) -> bool
where T: Any + Send + Sync,

Deletes a component of the node. Returns true if any component was deleted; otherwise returns false.

source

pub fn parent(&self) -> Option<Node>

source

pub fn children(&self) -> Vec<Node>

source

pub fn child_at(&self, index: usize) -> Option<Node>

source

pub fn num_children(&self) -> usize

Returns the number of children.

source

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.

source

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.

source

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.

source

pub fn swap_children( &self, child_1: impl AsRef<Node>, child_2: impl AsRef<Node> )

Swaps two children.

Panics

Panics if any of the specified nodes is not part of the node.

source

pub fn swap_children_by_indices(&self, child_1: usize, child_2: usize)

Swaps two children.

Panics

Panics if any of the specified indices is out of bounds.

source

pub fn remove_child(&self, child: impl AsRef<Node>) -> bool

Removes a child. Returns true if the child has been removed, or false otherwise.

source

pub fn remove_children(&self)

Removes all children nodes from the node.

source

pub fn remove_from_parent(&self) -> bool

Removes the node from its parent. Returns true if the child has been removed, or false otherwise.

source

pub fn name(&self) -> Option<String>

The name of the node as used in Node paths.

source

pub fn set_name(&self, name: Option<String>)

The name of the node as used in Node paths.

source

pub fn resolve_path(&self, path: &str) -> Option<Node>

Resolves an Node path. An Node path is resolved as follows:

  1. Let segments be the splitting of the path by the slash character (/).
  2. Let r be the initial node.
  3. For every segment s:
    1. If s == ".first", let r be the first child of r or otherwise None.
    2. If s == ".last", let r be the last child of r or otherwise None.
    3. If s == "..", let r be the parent of r or otherwise None.
    4. If s is non-empty, let r be a child of r such that child.name() == s or otherwise None.
  4. Return r
source

pub fn is<T: TryFrom<Self, Error = ClassError>>(&self) -> bool

Indicates whether an Node is of a certain Node subtype.

source

pub fn to<T: TryFrom<Self, Error = ClassError>>(&self) -> Result<T, ClassError>

Attempts to convert this Node reference into a T reference.

Trait Implementations§

source§

impl AsRef<Node> for Node

source§

fn as_ref(&self) -> &Node

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Node

source§

fn clone(&self) -> Self

Clones the node by reference.

Note: This method does not clone the node by content.

1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Node

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for Node

source§

fn hash<H: Hasher>(&self, state: &mut H)

Hashes the node by reference.

1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Node

source§

fn eq(&self, other: &Self) -> bool

Compares nodes by reference.

Note: This method does not compare the nodes by content.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Node

Auto Trait Implementations§

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnwindSafe for Node

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

§

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>,

§

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>,

§

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.