Timeline
Timeline
2025-10-27
init
This article summarizes the core knowledge points and common pitfalls encountered while learning the Rust language through rustlings exercises, covering key concepts such as variables and ownership mechanisms, enums and structs, error handling and traits, lazy evaluation of iterators, and how to safely share mutable state in multithreaded concurrent programming.
Environment Setup
1 | # Installation |
variable
Constant definitions must include a type!
variable6
1 | // TODO: Change the line below to fix the compiler error. |
move_semantics
Vec declaration must be mut, and parameters must also be mut
1 | fn fill_vec(mut vec: Vec<i32>) -> Vec<i32> { |
struct
… syntax
1 |
|
enum
Types of variants that an enum can hold
1 |
|
string
quiz2
1 | // This is a quiz for the following sections: |
hashmap
The entry method is very useful
1 | // We're collecting different fruits to bake a delicious fruit cake. For this, |
entry().and_modify().or_insert()
1 | // A list of scores (one per line) of a soccer match is given. Each line is of |
option
match takes ownership; you can use ref to declare that you get a reference type
1 |
|
You can also directly match on reference types
1 |
|
error_handling
Return a Box
1 | // This exercise is an altered version of the `errors4` exercise. It uses some |
map_error
1 | // Using catch-all error types like `Box<dyn Error>` isn't recommended for |
trait
trait default implementation
1 | trait Licensed { |
iterator
Iterator is lazy; nothing happens unless you call next or collect
1 |
|
Calculate factorial
1 | fn factorial(num: u64) -> u64 { |
map can transform the type being iterated over into another type to iterate
1 | // Let's define a simple model to track Rustlings' exercise progress. Progress |
smart pointers
std::borrow::Cow smart pointer
1 | // This exercise explores the `Cow` (Clone-On-Write) smart pointer. It can |
thread
Collect thread return values
1 | // This program spawns multiple threads that each runs for at least 250ms, and |
Threads share mutable state. In Rust, RefCell provides interior mutability only in single-threaded contexts; it cannot be safely used across threads. Therefore, wrapping RefCell in Arc is unsafe and will cause errors at compile time or runtime. To safely share and modify data across multiple threads, you need to use Arc<Mutex
1 | // Building on the last exercise, we want all of the threads to complete their |

