Struct atlist_rs::LinkedList [−][src]
A doubly-linked list in which the liftime of iterator is independent from self.
The LinkedList
allows pushing and popping elements at either end
in constant time.
Implementations
impl<T> LinkedList<T>
[src]
pub fn new() -> Self
[src]
Creates an empty LinkedList
.
Examples
use atlist_rs::LinkedList; let list: LinkedList<u32> = LinkedList::new();
pub fn len(&self) -> usize
[src]
Returns the length of the LinkedList
.
This operation should compute in O(1) time.
Examples
use atlist_rs::LinkedList; let mut dl = LinkedList::new(); let _ = dl.push_front(2); assert_eq!(dl.len(), 1); let _ = dl.push_front(1); assert_eq!(dl.len(), 2); let _ = dl.push_back(3); assert_eq!(dl.len(), 3);
pub fn is_empty(&self) -> bool
[src]
Returns true
if the LinkedList
is empty.
This operation should compute in O(1) time.
Examples
use atlist_rs::LinkedList; let mut dl = LinkedList::new(); assert!(dl.is_empty()); let _ = dl.push_front("foo"); assert!(!dl.is_empty());
pub fn clear(&mut self)
[src]
Removes all elements from the LinkedList
.
This operation should compute in O(n) time.
Examples
use atlist_rs::{LinkedList, LinkedListError}; let mut dl = LinkedList::new(); dl.push_front(2); dl.push_front(1); assert_eq!(dl.len(), 2); assert_eq!(*dl.front().unwrap(), 1); dl.clear(); assert_eq!(dl.len(), 0); assert_eq!(dl.front(), Err(LinkedListError::Empty));
pub fn iter(&self) -> Iter<T>ⓘNotable traits for Iter<T>
impl<T> Iterator for Iter<T> type Item = LinkedListItem<T>;
[src]
Notable traits for Iter<T>
impl<T> Iterator for Iter<T> type Item = LinkedListItem<T>;
Provides a forward iterator.
Examples
use atlist_rs::LinkedList; let mut list: LinkedList<u32> = LinkedList::new(); let _ = list.push_back(0); let _ = list.push_back(1); let _ = list.push_back(2); let mut iter = list.iter(); assert_eq!(*iter.next().unwrap(), 0); assert_eq!(*iter.next().unwrap(), 1); assert_eq!(*iter.next().unwrap(), 2); assert_eq!(iter.next(), None);
pub fn iter_mut(&mut self) -> IterMut<T>ⓘNotable traits for IterMut<T>
impl<T> Iterator for IterMut<T> type Item = LinkedListItem<T>;
[src]
Notable traits for IterMut<T>
impl<T> Iterator for IterMut<T> type Item = LinkedListItem<T>;
Provides a forward iterator.
Examples
use atlist_rs::LinkedList; use std::cell::RefCell; let mut list: LinkedList<RefCell<u32>> = LinkedList::new(); let _ = list.push_back(RefCell::new(0)); let _ = list.push_back(RefCell::new(1)); let _ = list.push_back(RefCell::new(2)); for element in list.iter_mut() { *(*element).borrow_mut() += 10; } let mut iter = list.iter_mut(); assert_eq!(*(*iter.next().unwrap()).borrow(), 10); assert_eq!(*(*iter.next().unwrap()).borrow(), 11); assert_eq!(*(*iter.next().unwrap()).borrow(), 12); assert_eq!(iter.next(), None);
pub fn iter_front(&self) -> Iter<T>ⓘNotable traits for Iter<T>
impl<T> Iterator for Iter<T> type Item = LinkedListItem<T>;
[src]
Notable traits for Iter<T>
impl<T> Iterator for Iter<T> type Item = LinkedListItem<T>;
Provides a iterator at the front element.
The iterator is pointing to the “ghost” non-element if the list is empty.
pub fn iter_back(&self) -> Iter<T>ⓘNotable traits for Iter<T>
impl<T> Iterator for Iter<T> type Item = LinkedListItem<T>;
[src]
Notable traits for Iter<T>
impl<T> Iterator for Iter<T> type Item = LinkedListItem<T>;
Provides a iterator at the back element.
The iterator is pointing to the “ghost” non-element if the list is empty.
pub fn iter_mut_front(&mut self) -> IterMut<T>ⓘNotable traits for IterMut<T>
impl<T> Iterator for IterMut<T> type Item = LinkedListItem<T>;
[src]
Notable traits for IterMut<T>
impl<T> Iterator for IterMut<T> type Item = LinkedListItem<T>;
Provides a iterator with editing operations at the front element.
The iterator is pointing to the “ghost” non-element if the list is empty.
pub fn iter_mut_back(&mut self) -> IterMut<T>ⓘNotable traits for IterMut<T>
impl<T> Iterator for IterMut<T> type Item = LinkedListItem<T>;
[src]
Notable traits for IterMut<T>
impl<T> Iterator for IterMut<T> type Item = LinkedListItem<T>;
Provides a iterator with editing operations at the back element.
The iterator is pointing to the “ghost” non-element if the list is empty.
pub fn push_front(&mut self, elt: T) -> LinkedListResult<()>
[src]
Adds an element first in the list.
This operation should compute in O(1) time.
pub fn pop_front(&mut self) -> LinkedListResult<LinkedListItem<T>>
[src]
Removes the first element and returns it, or None
if the list is
empty.
This operation should compute in O(1) time.
pub fn push_back(&mut self, elt: T) -> LinkedListResult<()>
[src]
Appends an element to the back of a list.
This operation should compute in O(1) time.
pub fn pop_back(&mut self) -> LinkedListResult<LinkedListItem<T>>
[src]
Removes the last element from a list and returns it, or None
if
it is empty.
This operation should compute in O(1) time.
pub fn front(&self) -> LinkedListResult<LinkedListItem<T>>
[src]
Provides a reference to the front element, or None
if the list is
empty.
Examples
use atlist_rs::{LinkedList, LinkedListError}; let mut dl = LinkedList::new(); assert_eq!(dl.front(), Err(LinkedListError::Empty)); let _ = dl.push_front(1); assert_eq!(*dl.front().unwrap(), 1);
pub fn back(&self) -> LinkedListResult<LinkedListItem<T>>
[src]
Provides a reference to the back element, or None
if the list is
empty.
Examples
use atlist_rs::{LinkedList, LinkedListError}; let mut dl = LinkedList::new(); assert_eq!(dl.back(), Err(LinkedListError::Empty)); let _ = dl.push_back(1); assert_eq!(*dl.back().unwrap(), 1);
pub fn contains_iter(&self, x: &Iter<T>) -> LinkedListResult<()>
[src]
Returns true
if the LinkedList
contains an element equal to the
given value.
Examples
use atlist_rs::{LinkedList, LinkedListError}; let mut list: LinkedList<u32> = LinkedList::new(); let mut another_list: LinkedList<u32> = LinkedList::new(); let _ = list.push_back(0); let _ = list.push_back(1); let _ = another_list.push_back(2); assert_eq!(list.contains_iter(&list.iter()), Ok(())); assert_eq!(list.contains_iter(&another_list.iter()), Err(LinkedListError::IteratorNotInList));
pub fn contains_iter_mut(&self, x: &IterMut<T>) -> LinkedListResult<()>
[src]
Returns true
if the LinkedList
contains an element equal to the
given value.
Examples
use atlist_rs::{LinkedList, LinkedListError}; let mut list: LinkedList<u32> = LinkedList::new(); let mut another_list: LinkedList<u32> = LinkedList::new(); let _ = list.push_back(0); let _ = list.push_back(1); let _ = another_list.push_back(2); let iter = list.iter_mut(); let another_iter = another_list.iter_mut(); assert_eq!(list.contains_iter_mut(&iter), Ok(())); assert_eq!(list.contains_iter_mut(&another_iter), Err(LinkedListError::IteratorNotInList));
pub fn insert_before(
&mut self,
iter: &IterMut<T>,
elt: T
) -> LinkedListResult<IterMut<T>>
[src]
&mut self,
iter: &IterMut<T>,
elt: T
) -> LinkedListResult<IterMut<T>>
Inserts a new element into the LinkedList
before the current one.
If the cursor is pointing at the “ghost” non-element then the new element is
inserted at the end of the LinkedList
.
Returns the iterator of inserted value if success, or error if failed
pub fn insert_after(
&mut self,
iter: &IterMut<T>,
elt: T
) -> LinkedListResult<IterMut<T>>
[src]
&mut self,
iter: &IterMut<T>,
elt: T
) -> LinkedListResult<IterMut<T>>
Inserts a new element into the LinkedList
after the current one.
If the cursor is pointing at the “ghost” non-element then the new element is
inserted at the front of the LinkedList
.
Returns the iterator of inserted value if success, or error if failed
pub fn remove_iter_mut(
&mut self,
iter: &mut IterMut<T>
) -> LinkedListResult<LinkedListItem<T>>
[src]
&mut self,
iter: &mut IterMut<T>
) -> LinkedListResult<LinkedListItem<T>>
Removes the current iterator from the LinkedList
.
The element that was removed is returned, the iterator will point to the “ghost” non-element.
If the iterator is currently pointing to the “ghost” non-element then
no element is removed and Err(LinkedListError::IteratorNotInList)
is
returned.
Trait Implementations
impl<T: Clone> Clone for LinkedList<T>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, other: &Self)
[src]
impl<T: Debug> Debug for LinkedList<T>
[src]
impl<T> Default for LinkedList<T>
[src]
impl<T: Eq> Eq for LinkedList<T>
[src]
impl<'a, T: 'a + Copy> Extend<&'a T> for LinkedList<T>
[src]
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
[src]
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
impl<T> Extend<T> for LinkedList<T>
[src]
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
[src]
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
impl<T> FromIterator<T> for LinkedList<T>
[src]
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
[src]
impl<T: Hash> Hash for LinkedList<T>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> IntoIterator for &LinkedList<T>
[src]
type Item = LinkedListItem<T>
The type of the elements being iterated over.
type IntoIter = Iter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Iter<T>ⓘNotable traits for Iter<T>
impl<T> Iterator for Iter<T> type Item = LinkedListItem<T>;
[src]
Notable traits for Iter<T>
impl<T> Iterator for Iter<T> type Item = LinkedListItem<T>;
impl<T> IntoIterator for &mut LinkedList<T>
[src]
type Item = LinkedListItem<T>
The type of the elements being iterated over.
type IntoIter = IterMut<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IterMut<T>ⓘNotable traits for IterMut<T>
impl<T> Iterator for IterMut<T> type Item = LinkedListItem<T>;
[src]
Notable traits for IterMut<T>
impl<T> Iterator for IterMut<T> type Item = LinkedListItem<T>;
impl<T: Ord> Ord for LinkedList<T>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T: PartialEq> PartialEq<LinkedList<T>> for LinkedList<T>
[src]
impl<T: PartialOrd> PartialOrd<LinkedList<T>> for LinkedList<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for LinkedList<T>
impl<T> Send for LinkedList<T> where
T: Send + Sync,
T: Send + Sync,
impl<T> Sync for LinkedList<T> where
T: Send + Sync,
T: Send + Sync,
impl<T> Unpin for LinkedList<T>
impl<T> UnwindSafe for LinkedList<T>
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>,