Trait len_trait::len::Len
[−]
[src]
pub trait Len { fn len(&self) -> usize; fn is_empty(&self) -> bool { ... } }
A trait for describing the length of a collection.
The amount of data stored in a collection, i.e. the amount of space it requires in memory, is
directly proportional to its length. For this reason, str
and other types measure their
lengths in code values (e.g. u8
), not code points (e.g. char
).
Obtaining the length of the collection must take a constant amount of time and space.
Required Methods
fn len(&self) -> usize
Returns the length of the collection.
Provided Methods
fn is_empty(&self) -> bool
Returns whether the collection is empty, i.e. if its length is zero.
This defaults to checking if len() == 0
, although can be overridden to be more efficient.
Implementors
impl<T> Len for [T]
impl Len for str
impl<K: Ord, V> Len for BTreeMap<K, V>
impl<T: Ord> Len for BTreeSet<T>
impl<T: Ord> Len for BinaryHeap<T>
impl<T> Len for LinkedList<T>
impl Len for String
impl<T> Len for Vec<T>
impl<T> Len for VecDeque<T>