Overview of Ticket Management chapter
mainTicket model by implementing a management system for storage and retrieval. This chapter introduces several core Rust concepts required to manage collections and data structures effectively.repository·main·Indexed 27 days ago
https://github.com/mainmatter/100-exercises-to-learn-rustA structured learning path consisting of 100 exercises designed to take developers from zero Rust knowledge to being able to write their own programs. The course covers fundamental Rust syntax and concepts, including functions, variables, primitive types, arithmetic operators, control flow, and panics. It includes a companion GitHub repository and an optional Workshop Runner (wr) CLI tool to guide users and verify solutions.
Ticket model by implementing a management system for storage and retrieval. This chapter introduces several core Rust concepts required to manage collections and data structures effectively.This chapter introduces asynchronous programming in Rust as an alternative to thread-based concurrency. You will learn about:
async/.await keywords: Used to write asynchronous code with a syntax similar to synchronous code.Future trait: A trait representing a computation that may not have completed yet.tokio: The industry-standard runtime used to execute asynchronous code.The Basic Calculator chapter uses calculator-based exercises to teach fundamental Rust syntax and concepts. By completing these exercises, you will learn:
This chapter introduces Rust's 'fearless concurrency' model by transitioning single-threaded applications to multithreaded ones. You will work with the following core concurrency primitives and concepts:
std::thread module.Arc, Mutex, and RwLock.Send and Sync traits.In Rust, data whose size is not known at compile time (like collections and strings) is stored on the heap.
When you define an async fn, the Rust compiler automatically transforms the function body into a state machine that implements the Future trait.
Each .await point in your code corresponds to a state in this generated state machine. This allows the future to pause its execution and return control to the runtime, resuming from the exact same state when polled again.
An integer overflow occurs when the result of an arithmetic operation exceeds the maximum value representable by the given integer type. An integer underflow occurs when the result is smaller than the minimum value of the type.
Rust does not perform automatic integer promotion (e.g., automatically converting a u8 to a u16 to accommodate a larger result). Instead, you must choose between two behaviors:
panic.u8::MAX + 1 becomes u8::MIN).Traits in Rust function as interfaces, defining shared behavior for different types. You will encounter traits in common operations such as .into() conversions and operators like == or +.
Key standard library traits covered in this section include:
Add, Sub, PartialEq for mathematical and comparison operations.From and Into for infallible type conversions.Clone and Copy for duplicating values.Deref and the mechanism of deref coercion.Sized to mark types with a known size at compile time.Drop for implementing custom cleanup logic when a value goes out of scope.attempt to divide by zero).In Rust, a package is defined by a Cargo.toml file (the manifest). A package can contain one or more crates (also known as targets).
There are two primary types of crates:
main function as the entry point.In Rust, a thread launched via thread::spawn is considered 'detached' in the sense that it can outlive the thread that spawned it. If a parent thread finishes and exits, its child threads will continue to run until the overall process terminates.
use std::thread;
fn f() {
thread::spawn(|| {
thread::spawn(|| {
loop {
thread::sleep(std::time::Duration::from_secs(1));
println!("Hello from the detached thread!");
}
});
});
}The stack is a LIFO (Last In, First Out) memory region. In Rust, data is allocated on the stack when its size is known at compile time (e.g., primitive integers like u32 or i64).
Key characteristics: