pub trait Collection: Extend<Self::Item> {
    type Item;

    // Required methods
    fn with_capacity(capacity: usize) -> Self;
    fn len(&self) -> usize;
    fn push(&mut self, elem: Self::Item);
    fn clear(&mut self);

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

Trait implemented by a collection types which need to support collection confinement.

Required Associated Types§

source

type Item

Item type contained within the collection.

Required Methods§

source

fn with_capacity(capacity: usize) -> Self

Creates new collection with certain capacity.

source

fn len(&self) -> usize

Returns the length of a collection.

source

fn push(&mut self, elem: Self::Item)

Pushes or inserts an element to the collection.

source

fn clear(&mut self)

Removes all elements from the collection.

Provided Methods§

source

fn is_empty(&self) -> bool

Detects whether collection is empty.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Collection for String

§

type Item = char

source§

fn with_capacity(capacity: usize) -> Self

source§

fn len(&self) -> usize

source§

fn push(&mut self, elem: Self::Item)

source§

fn clear(&mut self)

source§

impl Collection for AsciiString

§

type Item = AsciiChar

source§

fn with_capacity(capacity: usize) -> Self

source§

fn len(&self) -> usize

source§

fn push(&mut self, elem: Self::Item)

source§

fn clear(&mut self)

source§

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

§

type Item = (K, V)

source§

fn with_capacity(capacity: usize) -> Self

source§

fn len(&self) -> usize

source§

fn push(&mut self, elem: Self::Item)

source§

fn clear(&mut self)

source§

impl<K: Ord + Hash, V> Collection for BTreeMap<K, V>

§

type Item = (K, V)

source§

fn len(&self) -> usize

source§

fn push(&mut self, elem: Self::Item)

source§

fn clear(&mut self)

source§

impl<T> Collection for VecDeque<T>

§

type Item = T

source§

fn with_capacity(capacity: usize) -> Self

source§

fn len(&self) -> usize

source§

fn push(&mut self, elem: Self::Item)

source§

fn clear(&mut self)

source§

impl<T> Collection for Vec<T>

§

type Item = T

source§

fn with_capacity(capacity: usize) -> Self

source§

fn len(&self) -> usize

source§

fn push(&mut self, elem: Self::Item)

source§

fn clear(&mut self)

source§

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

§

type Item = T

source§

fn with_capacity(capacity: usize) -> Self

source§

fn len(&self) -> usize

source§

fn push(&mut self, elem: Self::Item)

source§

fn clear(&mut self)

source§

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

§

type Item = T

source§

fn len(&self) -> usize

source§

fn push(&mut self, elem: Self::Item)

source§

fn clear(&mut self)

Implementors§