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: Mut; fn swap(&mut self, i: usize, j: usize) where Self: Mut; fn insert(&mut self, index: usize, item: Self::Item) where Self: Own; fn remove(&mut self, index: usize) -> Option<Self::Item> where Self: Own; fn swap_remove(&mut self, index: usize) -> Option<Self::Item> where Self: Own; fn first(&self) -> Option<&Self::Item> { ... } fn first_mut(&mut self) -> Option<&mut Self::Item> where Self: Mut { ... } fn last(&self) -> Option<&Self::Item> { ... } fn last_mut(&mut self) -> Option<&mut Self::Item> where Self: Mut { ... } fn push(&mut self, item: Self::Item) where Self: Own { ... } fn pop(&mut self) -> Option<Self::Item> where Self: Own { ... } fn truncate(&mut self, len: usize) where Self: Own { ... } fn split_off(&mut self, index: usize) -> Self where Self: Sized + Own { ... } }
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: Mut
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: Mut
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: Own
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: Own
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: Own
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 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: Mut
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: Mut
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: Own
Pushes the given item onto the end of the list.
fn pop(&mut self) -> Option<Self::Item> where Self: Own
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: Own
Removes all items in the list starting at the given index.
Does nothing if len >= self.len()
.
fn split_off(&mut self, index: usize) -> Self where Self: Sized + Own
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()
.