Skip to main content

Tree

Struct Tree 

Source
pub struct Tree<T> { /* private fields */ }
Expand description

A tree where all values (T) are stored in a single contiguous list, and the inner tree (Nodes) is made up of branches with indices into the flat list.

This means fewer allocations when removing entire branches as we can reuse the memory for the values.

Implementations§

Source§

impl<T> Tree<T>

Source

pub const fn empty() -> Self

Create an empty tree

Source

pub fn view(&mut self) -> TreeView<'_, T>

Source

pub fn get_ref(&mut self, value_id: ValueId) -> Option<&T>

Get a refernence to a value

Source

pub fn get_mut(&mut self, value_id: ValueId) -> Option<&mut T>

Get a mutable refernence to a value

Source

pub fn values(self) -> TreeValues<T>

Consume the tree and return the values

Source

pub fn drain_removed(&mut self) -> impl DoubleEndedIterator<Item = ValueId> + '_

Drain the removed value ids. This will not return keys that have been replaced.

Source

pub fn with_value_mut<F, V>(&mut self, value_id: ValueId, f: F) -> V
where F: FnOnce(&[u16], &mut T, &mut Self) -> V,

Perform a given operation (F) on a mutable reference to a value in the tree while still having mutable access to the rest of the tree.

§Panics

This will panic if the value is already checked out

Trait Implementations§

Source§

impl<T: Debug> Debug for Tree<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Tree<T>

§

impl<T> RefUnwindSafe for Tree<T>
where T: RefUnwindSafe,

§

impl<T> Send for Tree<T>
where T: Send,

§

impl<T> Sync for Tree<T>
where T: Sync,

§

impl<T> Unpin for Tree<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Tree<T>

§

impl<T> UnwindSafe for Tree<T>
where 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.