Skip to content

pardhan03/deck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🃏 Simulates Card Project

A beginner-friendly Rust project that simulates a deck of playing cards. It helps demonstrate core Rust concepts like:

  • struct (for custom data types)
  • impl blocks (to implement methods)
  • Inherent implementations (methods associated directly with a struct)

📘 What You’ll Learn

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

🔧 Features

  • Deck Object that represents a full set of playing cards
  • new() — creates a fresh deck of cards
  • shuffle() — randomizes the deck
  • deal(n) — returns n number 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()!

🚀 Getting Started

# Clone the repository
git clone https://github.com/your-username/deck.git
cd deck

# Run the project without debug output
cargo run -q

About

A simple Rust project demonstrating how to build and manage a deck of cards using structs and basic methods like new(), shuffle(), and deal(). Perfect for learning Rust's struct-based design and encapsulation!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages