A beginner-friendly Rust project that simulates a deck of playing cards. It helps demonstrate core Rust concepts like:
struct(for custom data types)implblocks (to implement methods)- Inherent implementations (methods associated directly with a struct)
This project is built as a learning tool for:
- Defining and using
structs - Adding methods using
impl - Structuring logic and functionality in Rust
- Practicing ownership and borrowing basics
- Deck Object that represents a full set of playing cards
new()— creates a fresh deck of cardsshuffle()— randomizes the deckdeal(n)— returnsnnumber of cards from the deck
You're asking: "Where does the shuffle() method come from in Rust?"
Let’s get right to it 👇
✅ The shuffle() Method Comes From: rust Copy Edit use rand::seq::SliceRandom; This trait (SliceRandom) is what gives any slice (like &mut [T]) the .shuffle() method.
🧠 So How It Works Your Vec has a method .as_mut_slice() that gives a slice: &mut [T]
The SliceRandom trait extends slices with extra methods, including .shuffle()
When you use rand::seq::SliceRandom, you're bringing that trait into scope
Now Rust knows: “Ah, slices can use .shuffle()!
# Clone the repository
git clone https://github.com/your-username/deck.git
cd deck
# Run the project without debug output
cargo run -q