Trait eclectic::List
[−]
[src]
pub trait List: Collection + Iter + DrainRange<Range<usize>> + DrainRange<RangeFrom<usize>> + DrainRange<RangeTo<usize>> + DrainRange<RangeFull> { fn get(&self, index: usize) -> Option<&Self::Item>; fn get_mut(&mut self, index: usize) -> Option<&mut Self::Item> where Self: Mutate; fn swap(&mut self, i: usize, j: usize) where Self: Mutate; fn insert(&mut self, index: usize, item: Self::Item) where Self: AddRemove; fn remove(&mut self, index: usize) -> Option<Self::Item> where Self: AddRemove; fn swap_remove(&mut self, index: usize) -> Option<Self::Item> where Self: AddRemove; fn reverse(&mut self) where Self: Mutate { ... } fn first(&self) -> Option<&Self::Item> { ... } fn first_mut(&mut self) -> Option<&mut Self::Item> where Self: Mutate { ... } fn last(&self) -> Option<&Self::Item> { ... } fn last_mut(&mut self) -> Option<&mut Self::Item> where Self: Mutate { ... } fn push(&mut self, item: Self::Item) where Self: AddRemove { ... } fn pop(&mut self) -> Option<Self::Item> where Self: AddRemove { ... } fn truncate(&mut self, len: usize) where Self: AddRemove { ... } fn split_off(&mut self, index: usize) -> Self where Self: Sized + AddRemove { ... } }
A list.
A list is an ordered collection in which each item is located at a corresponding index. The indices are non-negative integers and zero-based.
Required Methods
fn get(&self, index: usize) -> Option<&Self::Item>
Returns a reference to the item at the given index in the list.
Returns None
if index >= self.len()
.
fn get_mut(&mut self, index: usize) -> Option<&mut Self::Item> where Self: Mutate
Returns a mutable reference to the item at the given index in the list.
Returns None
if index >= self.len()
.
fn swap(&mut self, i: usize, j: usize) where Self: Mutate
Swaps the items at the given indices in the list.
Panics
Panics if i >= self.len() || j >= self.len()
.
fn insert(&mut self, index: usize, item: Self::Item) where Self: AddRemove
Inserts the given item into the list at the given index.
All items after the given index are shifted one index to the right.
Panics
Panics if index > self.len()
.
fn remove(&mut self, index: usize) -> Option<Self::Item> where Self: AddRemove
Removes the item at the given index in the list and returns it.
Returns None
if index >= self.len()
.
All items after the given index are shifted one index to the left.
fn swap_remove(&mut self, index: usize) -> Option<Self::Item> where Self: AddRemove
Removes the item at the given index in the list and returns it, replacing it with the last item in the list.
Returns None
if index >= self.len()
.
Provided Methods
fn reverse(&mut self) where Self: Mutate
Reverses the order of the items in the list.
fn first(&self) -> Option<&Self::Item>
Returns a reference to the first item in the list.
Returns None
if the list is empty.
fn first_mut(&mut self) -> Option<&mut Self::Item> where Self: Mutate
Returns a mutable reference to the first item in the list.
Returns None
if the list is empty.
fn last(&self) -> Option<&Self::Item>
Returns a reference to the last item in the list.
Returns None
if the list is empty.
fn last_mut(&mut self) -> Option<&mut Self::Item> where Self: Mutate
Returns a mutable reference to the last item in the list.
Returns None
if the list is empty.
fn push(&mut self, item: Self::Item) where Self: AddRemove
Pushes the given item onto the back of the list.
fn pop(&mut self) -> Option<Self::Item> where Self: AddRemove
Removes the last item in the list and returns it.
Returns None
if the list was empty.
fn truncate(&mut self, len: usize) where Self: AddRemove
Ensures that the list's length is no more than the given length by removing the corresponding number of items from the back.
Does nothing if len >= self.len()
.
fn split_off(&mut self, index: usize) -> Self where Self: Sized + AddRemove
Splits the list in two at the given index.
Returns a new list that contains the items in the range index..self.len()
.
After this method returns, self
contains the items in the range 0..index
. self
's
capacity should remain the same, when possible.
Panics
Panics if index > self.len()
.