Skip to main content

Deck

Struct Deck 

Source
pub struct Deck<C: Copy + Clone + Debug + Ord + Display>(/* private fields */);
Expand description

Standard card deck

Implementations§

Source§

impl<C: Copy + Clone + Debug + Ord + Display> Deck<C>

Source

pub fn draw(&mut self) -> Result<C, DeckError>

Draw a card from the deck at random

§Errors

Returns an error if the deck is out of cards

Source

pub fn draw_random(&mut self) -> Result<C, DeckError>

Randomly draw a card

§Errors

Errors if there are no cards to draw

Source

pub fn draw_many_random(&mut self, count: usize) -> Vec<C>

Randomly draw up to cards, will stop early if out of cards This only shuffles the selected [count,len) range of cards For a mores random draw, use .shuffle() then .draw_many()

Source

pub fn draw_many(&mut self, count: usize) -> Vec<C>

Draw up to cards, will stop early if out of cards

Source

pub fn draw_rest(&mut self) -> Vec<C>

Draw the rest of the cards

Source

pub fn draw_rest_random(&mut self) -> Vec<C>

Randomly draw the rest of the cards

Source

pub fn insert(&mut self, card: C)

Insert a card into the deck

Source

pub fn into_vec(self) -> Vec<C>

Convert the dec into a vector of cards

Source

pub fn shuffle(&mut self)

Shuffle the deck

Source

pub fn peek(&self) -> Option<&C>

Peek at the next card

Source

pub fn from_cards(cards: Vec<C>) -> Self

Create a new deck of cards

Source

pub fn is_empty(&self) -> bool

Check if the deck is empty

Source

pub fn len(&self) -> usize

Length of the cards in the deck

Source

pub fn empty() -> Self

Create an empty deck of cards

Trait Implementations§

Source§

impl<C: Clone + Copy + Clone + Debug + Ord + Display> Clone for Deck<C>

Source§

fn clone(&self) -> Deck<C>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug + Copy + Clone + Debug + Ord + Display> Debug for Deck<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: DefaultCollection> Default for Deck<C>

Source§

fn default() -> Deck<C>

Returns the “default value” for a type. Read more
Source§

impl<'de, C> Deserialize<'de> for Deck<C>
where C: Deserialize<'de> + Copy + Clone + Debug + Ord + Display,

Source§

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<C: Eq + Copy + Clone + Debug + Ord + Display> Eq for Deck<C>

Source§

impl<C: Copy + Clone + Debug + Ord + Display> Extend<C> for Deck<C>

Source§

fn extend<I: IntoIterator<Item = C>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<C: Copy + Clone + Debug + Ord + Display> From<Vec<C>> for Deck<C>

Source§

fn from(cards: Vec<C>) -> Self

Converts to this type from the input type.
Source§

impl<C: Copy + Clone + Debug + Ord + Display> From<VecDeque<C>> for Deck<C>

Source§

fn from(cards: VecDeque<C>) -> Self

Converts to this type from the input type.
Source§

impl<C: Copy + Clone + Debug + Ord + Display> FromIterator<C> for Deck<C>

Source§

fn from_iter<I: IntoIterator<Item = C>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<C: Hash + Copy + Clone + Debug + Ord + Display> Hash for Deck<C>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<C: Copy + Clone + Debug + Ord + Display> IntoIterator for Deck<C>

Source§

type Item = C

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<C>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<C: Ord + Copy + Clone + Debug + Ord + Display> Ord for Deck<C>

Source§

fn cmp(&self, other: &Deck<C>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<C: PartialEq + Copy + Clone + Debug + Ord + Display> PartialEq for Deck<C>

Source§

fn eq(&self, other: &Deck<C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<C: PartialOrd + Copy + Clone + Debug + Ord + Display> PartialOrd for Deck<C>

Source§

fn partial_cmp(&self, other: &Deck<C>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<C> Serialize for Deck<C>
where C: Serialize + Copy + Clone + Debug + Ord + Display,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<C: PartialEq + Copy + Clone + Debug + Ord + Display> StructuralPartialEq for Deck<C>

Auto Trait Implementations§

§

impl<C> Freeze for Deck<C>

§

impl<C> RefUnwindSafe for Deck<C>
where C: RefUnwindSafe,

§

impl<C> Send for Deck<C>
where C: Send,

§

impl<C> Sync for Deck<C>
where C: Sync,

§

impl<C> Unpin for Deck<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for Deck<C>

§

impl<C> UnwindSafe for Deck<C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.