Skip to main content

Node

Struct Node 

Source
pub struct Node<T: Element = Value>(/* private fields */);
Expand description

A shared node of a tree: a whole tree, or a part of one.

Cloning one shares it, and two handles to one node have one Node::id. A list’s or a dictionary’s tree is made of nodes, which the lists and dictionaries made from it share: List::parts and Dict::root read the nodes a value is made of, Node::shape what each node holds, and Node::leaf and Node::branch build a tree again, node by node, so that what was shared stays shared.

Implementations§

Source§

impl<T: Element> Node<T>

Source

pub fn leaf(items: Vec<T>) -> Result<Self, StructureError>

Returns the leaf holding items.

§Errors

StructureError::Leaf unless they number from one to as many as a leaf of their kind holds.

Source

pub fn branch(left: Self, right: Self) -> Self

Returns the tree holding left’s elements, then right’s.

When the two are as high as each other or within one level, which they are whenever this crate made the tree being rebuilt, this is one new branch over exactly left and right, so each stays shared. Every tree here is balanced (AVL), and indexing, insertion, removal, joining and cutting rely on that for their cost; so when the two differ by more, as a tree from another writer may, the lower is joined into the higher’s near spine and the branches on that path are rebuilt balanced, in O(difference in height). Every node below that path stays shared, and the elements and their order are the same either way.

Source

pub fn id(&self) -> usize

Returns what tells this node apart from every other node alive: two handles answer alike exactly when they share one node. The answer means something only while a handle to the node is kept, since a node made after this one is dropped may answer the same.

Source

pub fn len(&self) -> usize

Returns how many elements lie in the tree.

Source

pub fn is_empty(&self) -> bool

Returns false: a node holds at least one element.

Source

pub fn window(&self, skip: usize, count: usize) -> Result<Self, StructureError>

Returns the tree of the count elements that follow this tree’s first skip, sharing every node the cut does not pass through.

§Errors

StructureError::Window unless count is at least one and the tree holds skip + count elements.

Source

pub fn height(&self) -> usize

Returns how many levels of branches lie below: 0 for a leaf.

Source

pub fn shape(&self) -> Shape<'_, T>

Returns what the node holds.

Trait Implementations§

Source§

impl<T: Element> Clone for Node<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Element> Debug for Node<T>

Source§

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

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

impl From<Node<Run>> for Text

Source§

fn from(root: Node<Run>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Forget for Node<T>

§

impl<T> Freeze for Node<T>
where *const ArcInner<Inner<T>> is !null: Freeze, PhantomData<ArcInner<Inner<T>>>: Freeze,

§

impl<T> Move for Node<T>

§

impl<T> RefUnwindSafe for Node<T>
where Atomic<usize>: RefUnwindSafe, T: RefUnwindSafe, <T as Sealed>::Measure: RefUnwindSafe, <T as Sealed>::Key: RefUnwindSafe,

§

impl<T> Send for Node<T>
where Arc<Inner<T>>: Send,

§

impl<T> Sync for Node<T>
where Arc<Inner<T>>: Sync,

§

impl<T> Unpin for Node<T>
where Arc<Inner<T>>: Unpin,

§

impl<T> UnsafeUnpin for Node<T>
where *const ArcInner<Inner<T>> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner<T>>>: UnsafeUnpin,

§

impl<T> UnwindSafe for Node<T>
where Arc<Inner<T>>: UnwindSafe,

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.