pub struct List<T: ?Sized + ListItem<ID>, const ID: u64 = 0> { /* private fields */ }Expand description
A linked list.
All elements in this linked list will be ListArc references to the value. Since a value can
only have one ListArc (for each pair of prev/next pointers), this ensures that the same
prev/next pointers are not used for several linked lists.
§Invariants
- If the list is empty, then
firstis null. Otherwise,firstpoints at theListLinksfield of the first element in the list. - All prev/next pointers in
ListLinksfields of items in the list are valid and form a cycle. - For every item in the list, the list owns the associated
ListArcreference and has exclusive access to theListLinksfield.
Implementations§
Source§impl<T: ?Sized + ListItem<ID>, const ID: u64> List<T, ID>
impl<T: ?Sized + ListItem<ID>, const ID: u64> List<T, ID>
Sourcepub fn push_back(&mut self, item: ListArc<T, ID>)
pub fn push_back(&mut self, item: ListArc<T, ID>)
Add the provided item to the back of the list.
Sourcepub fn push_front(&mut self, item: ListArc<T, ID>)
pub fn push_front(&mut self, item: ListArc<T, ID>)
Add the provided item to the front of the list.
Sourcepub unsafe fn remove(&mut self, item: &T) -> Option<ListArc<T, ID>>
pub unsafe fn remove(&mut self, item: &T) -> Option<ListArc<T, ID>>
Removes the provided item from this list and returns it.
This returns None if the item is not in the list. (Note that by the safety requirements,
this means that the item is not in any list.)
§Safety
item must not be in a different linked list (with the same id).
Sourcepub fn push_all_back(&mut self, other: &mut List<T, ID>)
pub fn push_all_back(&mut self, other: &mut List<T, ID>)
Moves all items from other into self.
The items of other are added to the back of self, so the last item of other becomes
the last item of self.
Sourcepub fn cursor_front(&mut self) -> Cursor<'_, T, ID>
pub fn cursor_front(&mut self) -> Cursor<'_, T, ID>
Returns a cursor that points before the first element of the list.
Sourcepub fn cursor_back(&mut self) -> Cursor<'_, T, ID>
pub fn cursor_back(&mut self) -> Cursor<'_, T, ID>
Returns a cursor that points after the last element in the list.