Struct deepmesa_lists::linkedlist::node::Node [−][src]
A handle to a node in the FastLinkedList
.
This struct wraps a raw pointer to memory but does not implement
the Deref
trait so you cannot dereference that pointer directly.
Handles can be used only by methods of the linkedlist that they
were obtained from. They can be copied and passed around by value
regardless of the lifetime of the linkedlist. Once the element
that the handle refers to is removed from the linked list, the
handle then becomes invalid. Passing an invalid handle into the
linked list is safe since all methods that accept a reference to a
handle return None
if the handle is invalid.
The
push_head()
,
push_tail()
,
push_next()
and
push_prev()
methods of FastLinkedList
return handles to the nodes pushed to the linked list. Handles can
only be used by passing them as arguments to the
next()
,
next_mut()
,
prev()
,
prev_mut()
,
prev_node()
,
next_node()
,
node()
,
node_mut()
,
has_next()
,
has_prev()
,
pop_next()
,
pop_prev()
,
pop_node()
,
push_next()
,
push_prev()
,
methods of the list. This allows adding, removing and mutating
elements in the middle of the list in O(1) time.
Handles can be copied, cloned and passed around by value or reference without regard to the lifetime of the list. When an element is removed from the list, the handle associated with that node becomes invalid forever. Passing an invalid handle to the list is safe since all methods that accept a reference to a handle return None if the handle is invalid.
Example
use deepmesa::lists::FastLinkedList; let mut list = FastLinkedList::<u8>::with_capacity(10); list.push_head(1); let middle = list.push_head(100); list.push_head(2); // get the value of the node in the middle of the list in O(1) // time. assert_eq!(list.node(&middle), Some(&100)); // remove the middle node in O(1) time list.pop_node(&middle); // once the middle node is removed, the handle is invalid assert_eq!(list.node(&middle), None); assert_eq!(list.len(), 2);
Node<T>
implements the Default
trait so you can store
default (invalid) handles in a struct and assign them later.
Example
use deepmesa::lists::FastLinkedList; use deepmesa::lists::linkedlist::Node; struct MyStruct<T> { handle: Node<T> }; let mut s = MyStruct::<u8>{ handle: Node::<u8>::default() }; let mut list = FastLinkedList::<u8>::with_capacity(10); // The default handle is invalid assert_eq!(list.node(&s.handle), None); // push a new element and store the handle s.handle = list.push_head(1); assert_eq!(list.node(&s.handle), Some(&1));
Trait Implementations
impl<T> Clone for Node<T>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Copy> Copy for Node<T>
[src]
impl<T: Debug> Debug for Node<T>
[src]
impl<T> Default for Node<T>
[src]
impl<T: Eq> Eq for Node<T>
[src]
impl<T: PartialEq> PartialEq<Node<T>> for Node<T>
[src]
impl<T> StructuralEq for Node<T>
[src]
impl<T> StructuralPartialEq for Node<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Node<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> !Send for Node<T>
impl<T> !Sync for Node<T>
impl<T> Unpin for Node<T>
impl<T> UnwindSafe for Node<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,