Struct nth_cons_list::List
[−]
[src]
pub struct List<A> { /* fields omitted */ }
An immutable cons list.
Examples
A list can be created using nil
and cons
.
use nth_cons_list::{cons, nil}; // A list containing `1, 2, 3` let list = cons(1, cons(2, cons(3, nil())));
Lists can be cheaply shared using .clone()
.
use std::fmt::Display; use nth_cons_list::*; fn print_list<A: Display>(list: List<A>) { println!("{}", list); } let list = cons(1, cons(2, cons(3, nil()))); print_list(list.clone());
Methods
impl<A> List<A>
[src]
fn head(&self) -> &A
[src]
fn tail(&self) -> List<A>
[src]
fn head_opt(&self) -> Option<&A>
[src]
Returns the first element of the list, or None
if
this list is empty.
fn tail_opt(&self) -> Option<List<A>>
[src]
Returns a list containing all elements except the first,
or None
if this list is empty.
fn is_empty(&self) -> bool
[src]
Tests whether this list is empty.
fn len(&self) -> usize
[src]
Returns the length of this list.
fn iter(&self) -> Iter<A>
[src]
Returns an iterator over the elements of this list.
fn reverse(&self) -> List<A> where
A: Clone,
[src]
A: Clone,
Returns a list with the elements in reverse order.
fn from_double_ended_iter<I: DoubleEndedIterator<Item = A>>(iter: I) -> List<A>
[src]
Creates a new list from a DoubleEndedIterator
.
Trait Implementations
impl<A> Clone for List<A>
[src]
fn clone(&self) -> Self
[src]
Clones the list by cloning a reference counted pointer to the list's contents; this operation is very cheap.
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'a, A: 'a> IntoIterator for &'a List<A>
[src]
type Item = &'a A
The type of the elements being iterated over.
type IntoIter = Iter<'a, A>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
Creates an iterator from a value. Read more
impl<A> FromIterator<A> for List<A>
[src]
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self
[src]
Creates a value from an iterator. Read more
impl<A: Display> Display for List<A>
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<A: Debug> Debug for List<A>
[src]
impl<A: PartialEq> PartialEq for List<A>
[src]
fn eq(&self, other: &List<A>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<A: Eq> Eq for List<A>
[src]
impl<A: Hash> Hash for List<A>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<A: PartialOrd> PartialOrd for List<A>
[src]
fn partial_cmp(&self, other: &List<A>) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<A: Ord> Ord for List<A>
[src]
fn cmp(&self, other: &List<A>) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more