Trait RandPop

Source
pub trait RandPop: Sized {
    type Item;

    // Required method
    fn rand_pop<R: Rng>(&mut self, rng: &mut R) -> Option<Self::Item>;

    // Provided method
    fn rand_iter<R: Rng>(self, rng: &mut R) -> RandIter<'_, Self, R>  { ... }
}
Expand description

Interface for randomly removing elements from a container.

Required Associated Types§

Source

type Item

Type of the item that’s removed from the container.

Required Methods§

Source

fn rand_pop<R: Rng>(&mut self, rng: &mut R) -> Option<Self::Item>

Randomly removes an item from the container; does not necessarily preserve order.

Provided Methods§

Source

fn rand_iter<R: Rng>(self, rng: &mut R) -> RandIter<'_, Self, R>

Randomly iterates through the items in this container, consuming the container.

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<T> RandPop for Vec<T>

Source§

type Item = T

Source§

fn rand_pop<R: Rng>(&mut self, rng: &mut R) -> Option<T>

Implementors§