A collection of Rust programming projects demonstrating fundamental concepts, algorithms, and advanced features like mutexes and async programming. Each project is a standalone Rust crate with its own Cargo.toml and source files, inspired by the Rust programming book and extended with custom implementations.
.
├── 1-hello_cargo
│ ├── Cargo.toml
│ └── src
│ └── main.rs # Basic "Hello, World!" program
├── 2-guessing_game
│ ├── Cargo.toml
│ └── src
│ └── main.rs # Number guessing game
├── 3-programming_concepts
│ ├── 3.1-temperature_conversion
│ │ ├── Cargo.toml
│ │ └── src
│ │ └── main.rs # Temperature converter
│ └── 3.2-nth_fibbonacci_number
│ ├── Cargo.toml
│ └── src
│ └── main.rs # Nth Fibonacci number generator
├── 4-collections
│ └── 4.1-mean_median_mode
│ ├── Cargo.toml
│ └── src
│ └── main.rs # Statistical calculations
├── 5-cryptographic_algorithms
│ └── 5.1-caeser_cipher
│ ├── Cargo.toml
│ └── src
│ └── main.rs # Caesar cipher implementation
├── 6-port_sniffer
│ ├── Cargo.toml
│ └── src
│ └── main.rs # Port scanning program
├── 7-io
│ ├── Cargo.toml
│ ├── src
│ │ ├── lib.rs # I/O library module
│ │ └── main.rs # File I/O with mutex and async examples
│ └── testing
│ ├── README.md # I/O testing documentation
│ ├── hello.txt # Sample text file
│ └── io # Directory for I/O test files
└── README.md # Project overview (this file)
To ensure compatibility with Cargo, rename project directories by removing numeric prefixes (e.g., change 2-guessing_game to guessing_game, 3.1-temperature_conversion to temperature_conversion). Update the corresponding Cargo.toml file's [package] section to reflect the new name:
[package]
name = "guessing_game" # Update to match renamed directory
version = "0.1.0"
edition = "2024"The projects progress from fundamental to advanced Rust concepts:
- Fundamentals: Ownership, borrowing, and lifetimes ensure memory safety without a garbage collector (e.g., in
7-iofor file handling). - Algorithms: Basic algorithms like Fibonacci sequence (
3.2-nth_fibbonacci_number) and statistical computations (4.1-mean_median_mode) showcase Rust's performance. - Collections: Use of
VecandHashMapin4.1-mean_median_modefor data manipulation. - Error Handling: Robust use of
ResultandOptiontypes (e.g., in6-port_snifferfor network operations). - Advanced Features: The
7-ioproject demonstrates advanced Rust concepts like mutexes for thread-safe file access and async programming for non-blocking I/O operations. Each project leverages Rust's zero-cost abstractions and compile-time checks for reliable, efficient code.
- Rust 1.70 or later
- Cargo (included with Rust)
- Install Rust and Cargo:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Clone the repository:
git clone <repository-url> cd rust-projects
- Rename project directories to remove numeric prefixes (e.g.,
2-guessing_gametoguessing_game) and updateCargo.tomlfiles accordingly.
- Navigate to a project directory (after renaming):
cd guessing_game - Build and run:
cargo run
- 1-hello_cargo: A basic "Hello, World!" program introducing Rust and Cargo.
- 2-guessing_game: A game where users guess a random number, demonstrating input handling and control flow.
- 3.1-temperature_conversion: Converts temperatures between Celsius and Fahrenheit, showcasing arithmetic and user input.
- 3.2-nth_fibbonacci_number: Generates the nth Fibonacci number, illustrating loops or recursion.
- 4.1-mean_median_mode: Computes mean, median, and mode of a number list, using collections like
VecandHashMap. - 5.1-caeser_cipher: Implements a Caesar cipher for text encryption/decryption, focusing on string manipulation.
- 6-port_sniffer: A port scanning program, demonstrating network programming and error handling.
- 7-io: Demonstrates file I/O operations with a library module (
lib.rs), including advanced features like mutexes for thread safety and async programming for non-blocking I/O.
To build all projects (after renaming directories):
find . -name "Cargo.toml" -execdir cargo build \;To run a specific project:
cd <renamed-project-directory>
cargo run- Rename directories to remove numeric prefixes for Cargo compatibility.
- The
7-ioproject includes atestingdirectory with sample files for I/O operations. - Ensure Rust is updated:
rustup update