take_some

Trait TakeSome

Source
pub trait TakeSome {
    type Item;

    // Required method
    fn take_some(&mut self) -> Option<Self::Item>;

    // Provided method
    fn split_at_some(self) -> Result<(Self::Item, Self), Self>
       where Self: Sized { ... }
}
Expand description

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.

Required Associated Types§

Source

type Item

An item of the collection.

Required Methods§

Source

fn take_some(&mut self) -> Option<Self::Item>

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§

Source

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

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§

Source§

impl<K> TakeSome for BTreeSet<K>
where K: Ord,

Source§

fn take_some(&mut self) -> Option<K>

Takes the “greatest” elements from the set.

unsafe under the cover!

Source§

type Item = K

Source§

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

Source§

fn take_some(&mut self) -> Option<K>

unsafe under the cover!

Source§

type Item = K

Source§

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

Source§

fn take_some(&mut self) -> Option<(K, V)>

Takes the “greatest” elements from the map.

unsafe under the cover!

Source§

type Item = (K, V)

Source§

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

Source§

fn take_some(&mut self) -> Option<(K, V)>

unsafe under the cover!

Source§

type Item = (K, V)

Source§

impl<T> TakeSome for Vec<T>

Source§

fn take_some(&mut self) -> Option<T>

Pops up the last element of the vector.

Source§

type Item = T

Implementors§