Skip to main content

Collection

Trait Collection 

Source
pub trait Collection {
    type Item;

    // Required method
    fn len(&self) -> usize;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn is_nonempty(&self) -> bool { ... }
}
Expand description

A trait for collections of items.

Required Associated Types§

Required Methods§

Source

fn len(&self) -> usize

Returns the number of items in the collection.

Provided Methods§

Source

fn is_empty(&self) -> bool

Checks whether the collection is empty.

Source

fn is_nonempty(&self) -> bool

Checks whether the collection is nonempty.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<K, V> Collection for BTreeMap<K, V>
where K: Ord,

Source§

type Item = (K, V)

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<K, V> Collection for HashMap<K, V>
where K: Eq + Hash,

Available on crate feature std only.
Source§

type Item = (K, V)

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<T, const N: usize> Collection for [T; N]

Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<T> Collection for BTreeSet<T>
where T: Ord,

Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<T> Collection for BinaryHeap<T>
where T: Ord,

Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<T> Collection for HashSet<T>
where T: Eq + Hash,

Available on crate feature std only.
Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<T> Collection for LinkedList<T>

Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<T> Collection for Vec<T>

Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<T> Collection for VecDeque<T>

Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl<T> Collection for [T]

Source§

type Item = T

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Implementors§