Trait eclectic::Collection [] [src]

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

    fn is_empty(&self) -> bool { ... }
    fn append(&mut self, other: &mut Self) where Self: Sized + AddRemove { ... }
    fn clear(&mut self) where Self: AddRemove { ... }
    fn with_capacity(capacity: usize) -> Self where Self: Sized + Default { ... }
    fn into_vec(self) -> Vec<Self::Item> where Self: Sized { ... }
}

A collection.

A collection maintains a finite number of items.

Associated Types

The type of the collection's items.

Required Methods

Returns the number of items in the collection.

Returns the number of items the collection can hold without reallocating.

Node-based collections should report a capacity of self.len().

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.

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.

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).

Shrinks the collection's capacity as much as possible.

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

Provided Methods

Checks if the collection contains no items.

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.

Removes all items from the collection.

Returns a new collection with the given capacity.

Collections (e.g. node-based ones) may ignore the capacity hint.

Converts the collection into a vector.

Implementors