NtreeNodeInterface

Trait NtreeNodeInterface 

Source
pub trait NtreeNodeInterface<const N: usize, T: Sized> {
Show 17 methods // Required methods fn get_data(&self) -> &T; fn get_data_mut(&mut self) -> &mut T; fn set_data(&mut self, data: T) -> T; unsafe fn peek_mut( &mut self, i: usize, ) -> Option<&mut dyn NtreeNodeInterface<N, T>>; unsafe fn peek(&self, i: usize) -> Option<&dyn NtreeNodeInterface<N, T>>; unsafe fn push_mut( &mut self, i: usize, data: T, ) -> &mut dyn NtreeNodeInterface<N, T>; unsafe fn pop(&mut self, i: usize) -> Option<T>; // Provided methods fn bounded_peek_mut( &mut self, i: usize, ) -> Option<&mut dyn NtreeNodeInterface<N, T>> { ... } fn bounded_peek( &mut self, i: usize, ) -> Option<&dyn NtreeNodeInterface<N, T>> { ... } fn bounded_push_mut( &mut self, i: usize, data: T, ) -> Option<&mut dyn NtreeNodeInterface<N, T>> { ... } unsafe fn push( &mut self, i: usize, data: T, ) -> &dyn NtreeNodeInterface<N, T> { ... } fn bounded_push( &mut self, i: usize, data: T, ) -> Option<&dyn NtreeNodeInterface<N, T>> { ... } unsafe fn peek_or_push( &mut self, i: usize, default_data: T, ) -> &dyn NtreeNodeInterface<N, T> { ... } fn bounded_peek_or_push( &mut self, i: usize, default_data: T, ) -> Option<&dyn NtreeNodeInterface<N, T>> { ... } unsafe fn peek_or_push_mut( &mut self, i: usize, default_data: T, ) -> &mut dyn NtreeNodeInterface<N, T> { ... } fn bounded_peek_or_push_mut( &mut self, i: usize, default_data: T, ) -> Option<&mut dyn NtreeNodeInterface<N, T>> { ... } fn bounded_pop(&mut self, i: usize) -> Option<T> { ... }
}
Expand description

Safe interface to a specific node in an n-tree.

Usage example:

use tasty_ntree::Ntree;

// Making a quadtree where each node holds a String.
let mut i32_octree = Ntree::<4, String>::new("Root node".to_string());

// As it was passed as the default value, the root node
// will hold a 5 as its data.
let root_data = i32_octree.interface().get_data();
println!("Found data: {:}", root_data);
assert_eq!(root_data, &"Root node".to_string());

let oct_interface = i32_octree.interface_mut();
//oct_interface.peek_or_push_mut(0, "This is node 0".to_string());
//oct_interface.peek_or_push_mut(3, "And this is node 3".to_string());
let node_2 = oct_interface.bounded_push_mut(2, "Hello from node 2".to_string()).expect("Array bounding error");

node_2
    .bounded_push_mut(1, "And 2.1".to_string())
    .expect("Array bounding error")
    .bounded_push_mut(3, "And 2.1.3".to_string());

node_2.bounded_push_mut(2, "And 2.2!".to_string());

#[cfg(feature = "debug")]
println!("Tree:\n{:?}", i32_octree);

// With the debug feature enabled, this would print:
// [NTree]
// 0 NtreeNode ( "Root node" )
// | 0 NTreeNode ( "This is node 0" )
// | 2 NTreeNode ( "Hello from node 2" )
// | | 1 NtreeNode ( "And 2.1" )
// | | | 3 NtreeNode ( "And 2.1.3" )
// | | 2 NtreeNode ( "And 2.2!" )
// | 3 NtreeNode ( "And this is node 3" )

Required Methods§

Source

fn get_data(&self) -> &T

Returns a reference to the data in this node.

Source

fn get_data_mut(&mut self) -> &mut T

Returns a mutable reference to the data in this node.

Source

fn set_data(&mut self, data: T) -> T

Sets data inside this node to new value and returns old value.

Source

unsafe fn peek_mut( &mut self, i: usize, ) -> Option<&mut dyn NtreeNodeInterface<N, T>>

Returns a mutable reference to an interface to child node i if it exists.

Panics if i is bigger than the ammount of children the node has.

Source

unsafe fn peek(&self, i: usize) -> Option<&dyn NtreeNodeInterface<N, T>>

Returns a reference to an interface to child node i if it exists.

Panics if i is bigger than the ammount of children the node has.

Source

unsafe fn push_mut( &mut self, i: usize, data: T, ) -> &mut dyn NtreeNodeInterface<N, T>

If child node ‘i’ exists, overwrites it.

If it doesn’t, creates it and returns a mutable reference to it.

If you only want to create a child if one doesn’t already exist, use [peek_or_push] or [peek_or_push_mut].

Panics if i is bigger than the ammount of children the node has.

Source

unsafe fn pop(&mut self, i: usize) -> Option<T>

Pops child node ‘i’ and returns an optional value representing inner data.

Returns Some(data) if it existed, None if it didn’t.

Panics if i is bigger than the ammount of children the node has.

Provided Methods§

Source

fn bounded_peek_mut( &mut self, i: usize, ) -> Option<&mut dyn NtreeNodeInterface<N, T>>

Returns a mutable reference to an interface to child node i if it exists.

Does bounds checking at runtime.

Source

fn bounded_peek(&mut self, i: usize) -> Option<&dyn NtreeNodeInterface<N, T>>

Returns a reference to an interface to child node i if it exists.

Does bounds checking at runtime.

Source

fn bounded_push_mut( &mut self, i: usize, data: T, ) -> Option<&mut dyn NtreeNodeInterface<N, T>>

If child node ‘i’ exists, overwrites it.

If it doesn’t, creates it and returns a mutable reference to it (as long as i is within bounds).

Does bounds checking at runtime. If i is out of bounds, returns None.

Source

unsafe fn push(&mut self, i: usize, data: T) -> &dyn NtreeNodeInterface<N, T>

If child node ‘i’ exists, overwrites it.

If it doesn’t, creates it and returns a reference to it.

If you only want to create a child if one doesn’t already exist, use [peek_or_push] or [peek_or_push_mut].

Panics if i is bigger than the ammount of children the node has.

Source

fn bounded_push( &mut self, i: usize, data: T, ) -> Option<&dyn NtreeNodeInterface<N, T>>

If child node ‘i’ exists, overwrites it.

If it doesn’t, creates it and returns a reference to it (as long as i is within bounds).

Does bounds checking at runtime. If i is out of bounds, returns None.

Source

unsafe fn peek_or_push( &mut self, i: usize, default_data: T, ) -> &dyn NtreeNodeInterface<N, T>

Returns a reference to an interface to child node i if it exists, if not, creates it and returns it.

Panics if i is bigger than the ammount of children the node has.

Source

fn bounded_peek_or_push( &mut self, i: usize, default_data: T, ) -> Option<&dyn NtreeNodeInterface<N, T>>

Returns a reference to an interface to child node i if it exists, if not, creates it and returns it (as long as i is within bounds).

Does bounds checking at runtime. If i is out of bounds, returns None.

Source

unsafe fn peek_or_push_mut( &mut self, i: usize, default_data: T, ) -> &mut dyn NtreeNodeInterface<N, T>

Returns a mutable reference to an interface to child node i if it exists, if not, creates it and returns it.

Panics if i is bigger than the ammount of children the node has.

Source

fn bounded_peek_or_push_mut( &mut self, i: usize, default_data: T, ) -> Option<&mut dyn NtreeNodeInterface<N, T>>

Returns a mutable reference to an interface to child node i if it exists, if not, creates it and returns it (as long as i is within bounds).

Does bounds checking at runtime.

Source

fn bounded_pop(&mut self, i: usize) -> Option<T>

Pops child node ‘i’ and returns an optional value representing inner data.

Returns Some(data) if it existed, None if it didn’t.

Does bounds checking at runtime.

Implementors§