TryPush

Trait TryPush 

Source
pub trait TryPush {
    type Item;
    type Error;
    type ItemView<'a>
       where Self: 'a;

    // Required method
    fn try_push<'a>(
        &'a mut self,
        item: Self::Item,
    ) -> Result<Self::ItemView<'a>, Self::Error>;
}
Expand description

Abstracts something you can try push item into &mut self

Required Associated Types§

Source

type Item

Item stocked in the collection

Source

type Error

The error returned by the collection if push fail

Source

type ItemView<'a> where Self: 'a

Represent a way to access Item in the collection directly after push

Required Methods§

Source

fn try_push<'a>( &'a mut self, item: Self::Item, ) -> Result<Self::ItemView<'a>, Self::Error>

Try to push an item into a collection, no guarantee on ordering.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TryPush for ()

Source§

type Error = Infallible

Source§

type Item = ()

Source§

type ItemView<'a> = ()

Source§

fn try_push(&mut self, _: Self::Item) -> Result<Self::ItemView<'_>, Self::Error>

Source§

impl TryPush for String

Available on crate feature alloc only.
Source§

type Error = (<String as TryPush>::Item, TryReserveError)

Source§

type Item = char

Source§

type ItemView<'a> = <String as TryPush>::Item

Source§

fn try_push<'a>( &'a mut self, c: Self::Item, ) -> Result<Self::ItemView<'a>, Self::Error>

Source§

impl<Item> TryPush for LinkedList<Item>

Available on crate feature alloc only.
Source§

type Error = (<LinkedList<Item> as TryPush>::Item, TryReserveError)

Source§

type Item = Item

Source§

type ItemView<'a> = &'a mut <LinkedList<Item> as TryPush>::Item where Self: 'a

Source§

fn try_push<'a>( &'a mut self, item: Self::Item, ) -> Result<Self::ItemView<'a>, Self::Error>

Source§

impl<Item> TryPush for VecDeque<Item>

Available on crate feature alloc only.
Source§

type Error = (<VecDeque<Item> as TryPush>::Item, TryReserveError)

Source§

type Item = Item

Source§

type ItemView<'a> = &'a mut <VecDeque<Item> as TryPush>::Item where Self: 'a

Source§

fn try_push<'a>( &'a mut self, item: Self::Item, ) -> Result<Self::ItemView<'a>, Self::Error>

Source§

impl<Item> TryPush for Vec<Item>

Available on crate feature alloc only.
Source§

type Error = (<Vec<Item> as TryPush>::Item, TryReserveError)

Source§

type Item = Item

Source§

type ItemView<'a> = &'a mut <Vec<Item> as TryPush>::Item where Self: 'a

Source§

fn try_push<'a>( &'a mut self, item: Self::Item, ) -> Result<Self::ItemView<'a>, Self::Error>

Source§

impl<Item, const N: usize> TryPush for SmallVec<[Item; N]>

Available on crate feature smallvec only.
Source§

type Error = (<SmallVec<[Item; N]> as TryPush>::Item, CollectionAllocErr)

Source§

type Item = Item

Source§

type ItemView<'a> = &'a mut <SmallVec<[Item; N]> as TryPush>::Item where Self: 'a

Source§

fn try_push<'a>( &'a mut self, item: Self::Item, ) -> Result<Self::ItemView<'a>, Self::Error>

Source§

impl<Item: Eq + Hash, Seed: BuildHasher> TryPush for HashSet<Item, Seed>

Available on crate feature hashmap only.
Source§

type Error = (<HashSet<Item, Seed> as TryPush>::Item, TryReserveError)

Source§

type Item = Item

Source§

type ItemView<'a> = bool where Self: 'a

Source§

fn try_push<'a>( &'a mut self, item: Self::Item, ) -> Result<Self::ItemView<'a>, Self::Error>

Source§

impl<Item: Ord> TryPush for BinaryHeap<Item>

Available on crate feature alloc only.
Source§

type Error = (<BinaryHeap<Item> as TryPush>::Item, TryReserveError)

Source§

type Item = Item

Source§

type ItemView<'a> = () where Self: 'a

Source§

fn try_push<'a>( &'a mut self, item: Self::Item, ) -> Result<Self::ItemView<'a>, Self::Error>

Source§

impl<Item: Ord> TryPush for BTreeSet<Item>

Available on crate feature alloc only.
Source§

type Error = (<BTreeSet<Item> as TryPush>::Item, TryReserveError)

Source§

type Item = Item

Source§

type ItemView<'a> = bool where Self: 'a

Source§

fn try_push( &mut self, item: Self::Item, ) -> Result<Self::ItemView<'_>, Self::Error>

Source§

impl<Key: Eq + Hash, Value, Seed: BuildHasher> TryPush for HashMap<Key, Value, Seed>

Available on crate feature hashmap only.
Source§

type Error = (<HashMap<Key, Value, Seed> as TryPush>::Item, TryReserveError)

Source§

type Item = (Key, Value)

Source§

type ItemView<'a> = Option<Value> where Self: 'a

Source§

fn try_push<'a>( &'a mut self, item: Self::Item, ) -> Result<Self::ItemView<'a>, Self::Error>

Source§

impl<Key: Ord, Value> TryPush for BTreeMap<Key, Value>

Available on crate feature alloc only.
Source§

type Error = (<BTreeMap<Key, Value> as TryPush>::Item, TryReserveError)

Source§

type Item = (Key, Value)

Source§

type ItemView<'a> = Option<Value> where Self: 'a

Source§

fn try_push<'a>( &'a mut self, item: Self::Item, ) -> Result<Self::ItemView<'a>, Self::Error>

Implementors§