Trait take_some::TakeSome[][src]

pub trait TakeSome {
    type Item;
    fn take_some(&mut self) -> Option<Self::Item>;

    fn split_at_some(self) -> Result<(Self::Item, Self), Self>
    where
        Self: Sized
, { ... } }

A helper trait that allows to take some value out of a collection, i.e. remove a single element and return it, while preserving all others.

Associated Types

An item of the collection.

Required Methods

Takes "some" element from a collection while preserving all others.

In general case it could not be defined which exactly element will be returned (first, last, greatest, least, ...), so, I repeat, in general case it is better to make no assumptions on the ordering or anything else.

There are several assumptions that trait implementors should take care of:

  • None should be returned if and only if the collection is empty.
  • If the collection is NOT empty, exactly ONE element should be taken out from it, i.e. all the rest items should remains there.
  • In case the collection IS empty, this call should NOT modify the collection.
  • The implementors are encouraged to implement the method in a way that it will cause the least overhead possible.

Provided Methods

Splits a given collection at "some" element, and returns a pair of that element and the remaining collection, if "some" element was found, or returns the original collection if "some" element could not be found. The latter happens if the collection is empty.

Implementations on Foreign Types

impl<K, V> TakeSome for BTreeMap<K, V> where
    K: Ord
[src]

Takes the "greatest" elements from the map.

unsafe under the cover!

impl<K> TakeSome for BTreeSet<K> where
    K: Ord
[src]

Takes the "greatest" elements from the set.

unsafe under the cover!

impl<K, V, S> TakeSome for HashMap<K, V, S> where
    K: Eq + Hash,
    S: BuildHasher
[src]

unsafe under the cover!

impl<K, S> TakeSome for HashSet<K, S> where
    K: Hash + Eq,
    S: BuildHasher
[src]

unsafe under the cover!

impl<T> TakeSome for Vec<T>
[src]

Pops up the last element of the vector.

Implementors