pub trait NodeApi {
// Required methods
fn id(self: &Arc<Self>) -> &NodeId;
fn create_child(self: &Arc<Self>) -> Result<Arc<Node>, Box<dyn Error>>;
fn create_child_at(
self: &Arc<Self>,
index: usize,
) -> Result<Arc<Node>, Box<dyn Error>>;
fn create_child_with_id(
self: &Arc<Self>,
id: impl Into<NodeId>,
) -> Result<Arc<Node>, Box<dyn Error>>;
fn create_child_with_id_at(
self: &Arc<Self>,
id: impl Into<NodeId>,
index: usize,
) -> Result<Arc<Node>, Box<dyn Error>>;
fn move_to(
self: &Arc<Self>,
parent: &Node,
index: Option<usize>,
) -> Result<(), Box<dyn Error>>;
fn move_before(
self: &Arc<Self>,
other: &Arc<Node>,
) -> Result<(), Box<dyn Error>>;
fn move_after(
self: &Arc<Self>,
other: &Arc<Node>,
) -> Result<(), Box<dyn Error>>;
fn children(self: &Arc<Self>) -> Vec<Arc<Node>>;
fn parent(self: &Arc<Self>) -> Option<Arc<Node>>;
fn siblings(self: &Arc<Self>) -> Vec<Arc<Node>>;
fn depth(self: &Arc<Self>) -> usize;
}
Expand description
Required Methods§
Sourcefn create_child(self: &Arc<Self>) -> Result<Arc<Node>, Box<dyn Error>>
fn create_child(self: &Arc<Self>) -> Result<Arc<Node>, Box<dyn Error>>
Creates a new child node with a generated ID.
Sourcefn create_child_at(
self: &Arc<Self>,
index: usize,
) -> Result<Arc<Node>, Box<dyn Error>>
fn create_child_at( self: &Arc<Self>, index: usize, ) -> Result<Arc<Node>, Box<dyn Error>>
Creates a new child node with a generated ID at the given index in the parent’s children.
Sourcefn create_child_with_id(
self: &Arc<Self>,
id: impl Into<NodeId>,
) -> Result<Arc<Node>, Box<dyn Error>>
fn create_child_with_id( self: &Arc<Self>, id: impl Into<NodeId>, ) -> Result<Arc<Node>, Box<dyn Error>>
Creates a new child node with the given ID at the end of the parent’s children.
Sourcefn create_child_with_id_at(
self: &Arc<Self>,
id: impl Into<NodeId>,
index: usize,
) -> Result<Arc<Node>, Box<dyn Error>>
fn create_child_with_id_at( self: &Arc<Self>, id: impl Into<NodeId>, index: usize, ) -> Result<Arc<Node>, Box<dyn Error>>
Creates a new child node with the given ID at the given index in the parent’s children.
Sourcefn move_to(
self: &Arc<Self>,
parent: &Node,
index: Option<usize>,
) -> Result<(), Box<dyn Error>>
fn move_to( self: &Arc<Self>, parent: &Node, index: Option<usize>, ) -> Result<(), Box<dyn Error>>
Moves the node to the given parent, placing it in that parent’s children at the given index.
Given:
<ROOT>
├──A
│ ├──C
│ ├──D
│ └──E
└──B
If we call B.move_to(&A, Some(1))
, we get:
<ROOT>
└──A
├──C
├──B
├──D
└──E
Passing None
as the index moves the node to the end of the parent’s children.
Sourcefn move_before(
self: &Arc<Self>,
other: &Arc<Node>,
) -> Result<(), Box<dyn Error>>
fn move_before( self: &Arc<Self>, other: &Arc<Node>, ) -> Result<(), Box<dyn Error>>
Moves the node before the given node.
Given:
<ROOT>
├──A
│ ├──C
│ ├──D
│ └──E
└──B
If we call B.move_before(&E)
, we get:
<ROOT>
└──A
├──C
├──D
├──B
└──E
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.