Trait eclectic::Collection [] [src]

pub trait Collection {
    type Item;
    fn len(&self) -> usize;
    fn extend_object(&mut self, items: &mut Iterator<Item=Self::Item>) where Self: Own;
    fn drain<'a>(&'a mut self) -> Box<Iterator<Item=Self::Item> + 'a> where Self: Own;
    fn reserve(&mut self, additional: usize) where Self: Own;
    fn shrink_to_fit(&mut self) where Self: Own;

    fn is_empty(&self) -> bool { ... }
    fn append(&mut self, other: &mut Self) where Self: Sized + Own { ... }
    fn clear(&mut self) where Self: Own { ... }
}

A collection.

A collection maintains a finite number of items.

Associated Types

type Item

The type of the collection's items.

Required Methods

fn len(&self) -> usize

Returns the number of items in the collection.

fn extend_object(&mut self, items: &mut Iterator<Item=Self::Item>) where Self: Own

Inserts the items yielded by the given iterator into the collection.

This method is provided for use with trait objects, and generic code should prefer Extend::extend, which this method must be equivalent to.

The exact behavior of this method is unspecified, but may be refined by subtraits.

Note that this trait cannot extend Extend due to object-safety limitations.

fn drain<'a>(&'a mut self) -> Box<Iterator<Item=Self::Item> + 'a> where Self: Own

Removes all items from the collection and returns an iterator that yields them.

All items are removed even if the iterator is not exhausted. However, the behavior of this method is unspecified if the iterator is leaked (e.g. via mem::forget).

The iteration order is unspecified, but subtraits may place a requirement on it.

self's capacity should remain the same, when possible.

fn reserve(&mut self, additional: usize) where Self: Own

Reserves capacity for the given number of additional items to be inserted into the collection.

This method may do nothing (e.g. for node-based collections).

fn shrink_to_fit(&mut self) where Self: Own

Shrinks the collection's capacity as much as possible.

This method may do nothing (e.g. for node-based collections).

Provided Methods

fn is_empty(&self) -> bool

Checks if the collection contains no items.

fn append(&mut self, other: &mut Self) where Self: Sized + Own

Drains the given collection and inserts its items into the collection.

The exact behavior of this method is unspecified, but it must be equivalent to self.extend_object(&mut other.drain()). other's capacity should remain the same, when possible.

fn clear(&mut self) where Self: Own

Removes all items from the collection.

Implementors