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

Returns the length of the collection.

Provided Methods

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