Struct bern_kernel::mem::linked_list::LinkedList
source · [−]pub struct LinkedList<T> { /* private fields */ }Expand description
A doubly-linked list owning its nodes.
Based on std::collections::LinkedList and https://rust-unofficial.github.io/too-many-lists.
Examples
Create a new list:
let mut list_a = LinkedList::new();
let mut list_b = LinkedList::new();Add element to the end of a list with an allocator:
static ALLOCATOR: Bump = unsafe { Bump::new(NonNull::new_unchecked(0x2001E000 as *mut u8), 5_000) };
list_a.emplace_back(MyStruct { id: 42 }, &ALLOCATOR);
list_a.emplace_back(MyStruct { id: 54 }, &ALLOCATOR);Nodes in the same list can be allocated in different memory sections.
Move an element from one to another list:
let node = list_a.pop_front();
list_a.push_back(node);Implementations
sourceimpl<T> LinkedList<T>
impl<T> LinkedList<T>
sourcepub fn emplace_back(
&self,
element: T,
alloc: &'static dyn Allocator
) -> Result<(), AllocError>
pub fn emplace_back(
&self,
element: T,
alloc: &'static dyn Allocator
) -> Result<(), AllocError>
Allocate a new element and move it to the end of the list
Note: This fails when we’re out of memory
sourcepub fn pop_front(&self) -> Option<Box<Node<T>>>
pub fn pop_front(&self) -> Option<Box<Node<T>>>
Remove and return the first node from the list if there is any
sourcepub fn insert(&self, node: NonNull<Node<T>>, new_node: Box<Node<T>>)
pub fn insert(&self, node: NonNull<Node<T>>, new_node: Box<Node<T>>)
Insert a node exactly before a given node
Note: prefer Self::insert_when() if possible
sourcepub fn insert_when(&self, node: Box<Node<T>>, criteria: impl Fn(&T, &T) -> bool)
pub fn insert_when(&self, node: Box<Node<T>>, criteria: impl Fn(&T, &T) -> bool)
Insert a node before the first succeeding match given a comparison criteria.
Example
Insert task pausing before the element where the next wake-up time
next_wut() is larger than the one of pausing.
/* create and populate list */
let pausing: Task = /* omitted */;
tasks_sleeping.insert_when(
pausing,
|pausing, task| {
pausing.next_wut() > task.next_wut()
});sourcepub fn front(&self) -> Option<&T>
pub fn front(&self) -> Option<&T>
Get a reference to the first value of the list if there is a node
sourcepub fn iter(&self) -> Iter<'_, T>ⓘNotable traits for Iter<'a, T>impl<'a, T> Iterator for Iter<'a, T> type Item = &'a T;
pub fn iter(&self) -> Iter<'_, T>ⓘNotable traits for Iter<'a, T>impl<'a, T> Iterator for Iter<'a, T> type Item = &'a T;
Provides a forward iterator.
sourcepub fn iter_mut(&self) -> IterMut<'_, T>ⓘNotable traits for IterMut<'a, T>impl<'a, T> Iterator for IterMut<'a, T> type Item = &'a mut T;
pub fn iter_mut(&self) -> IterMut<'_, T>ⓘNotable traits for IterMut<'a, T>impl<'a, T> Iterator for IterMut<'a, T> type Item = &'a mut T;
Provides a forward iterator with mutable references.
sourcepub fn cursor_front_mut(&self) -> Cursor<'_, T>
pub fn cursor_front_mut(&self) -> Cursor<'_, T>
Provides a cursor with editing operation at the front element.
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for LinkedList<T>
impl<T> Send for LinkedList<T>
impl<T> Sync for LinkedList<T>
impl<T> Unpin for LinkedList<T>
impl<T> UnwindSafe for LinkedList<T> where
T: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more