pub struct Pile<T> { /* private fields */ }Expand description
An ordered pile of items with deterministic operations.
The “top” is the end of the pile: draw takes from the top
and put adds to it. Shuffling is deterministic given a
Prng, and the pile carries no generator of its own, so it snapshots and
replays with whatever state it lives in. This is an opt-in helper; a game’s
State can hold piles or plain fields as it prefers.
Implementations§
Source§impl<T> Pile<T>
impl<T> Pile<T>
Sourcepub const fn from_items(items: Vec<T>) -> Self
pub const fn from_items(items: Vec<T>) -> Self
Creates a pile from items, with the last element on top.
Sourcepub fn draw_n(&mut self, n: usize) -> Vec<T>
pub fn draw_n(&mut self, n: usize) -> Vec<T>
Removes up to n items from the top, returned top-first.
Sourcepub fn put_bottom(&mut self, item: T)
pub fn put_bottom(&mut self, item: T)
Adds an item to the bottom.
Sourcepub fn insert(&mut self, index: usize, item: T)
pub fn insert(&mut self, index: usize, item: T)
Inserts an item at index (clamped to the length), preserving order.
Use this to reverse a draw exactly, e.g. in a Reversible undo.
Sourcepub fn remove(&mut self, index: usize) -> Option<T>
pub fn remove(&mut self, index: usize) -> Option<T>
Removes and returns the item at index, or None if out of range.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Pile<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Pile<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T> FromIterator<T> for Pile<T>
impl<T> FromIterator<T> for Pile<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
Source§impl<'a, T> IntoIterator for &'a Pile<T>
impl<'a, T> IntoIterator for &'a Pile<T>
impl<T: Eq> Eq for Pile<T>
impl<T> StructuralPartialEq for Pile<T>
Auto Trait Implementations§
impl<T> Freeze for Pile<T>
impl<T> RefUnwindSafe for Pile<T>where
T: RefUnwindSafe,
impl<T> Send for Pile<T>where
T: Send,
impl<T> Sync for Pile<T>where
T: Sync,
impl<T> Unpin for Pile<T>where
T: Unpin,
impl<T> UnsafeUnpin for Pile<T>
impl<T> UnwindSafe for Pile<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more