RustGuess is a command-line guessing game that provides a very interesting example for new Rust developers or those transitioning from other languages.
If you've completed the basic syntax lessons, this project is designed to be your next step—a practical, working application to clone and study.
This small project demonstrates real-world Rust application structure by tackling several key concepts:
- Modular Design: Code is cleanly separated into modules (e.g.,
user_data,data_handler). - Data Persistence: Reading and writing user statistics to JSON files using
serdeandstd::fs. - Advanced Error Handling: A robust error system using custom enums (
GameError) and dynamic boxed errors (BoxedError) for clean error propagation. - Idiomatic I/O: Using the
?operator andResultfor safe input handling. - Asynchronous Programming: Introduction to
async/awaitandtokiofor non-blocking operations. - Web Integration & Testing: Basic setup for a local Web API and writing tests with mock inputs.
You need the Rust toolchain installed.
-
Clone & Run:
git clone https://github.com/QwQ-dev/RustGuess.git cd RustGuess cargo run -
Usage: The game will prompt you for a username, load or create your stats, and then begin the guessing loop. Type
exit,quit, orendto quit the game gracefully.
Further examine the code; this may be quite useful for newcomers diving into Rust!