Ownership ensure automatic memory clean up when a variable that owns data goes out of scope. This prevents memory leaks. Borrowing allows using a value without taking ownership of it. The borrowing rules prevent data races by ensuring that either multiple parts of the code can read the data, or one part can modify it, but not both at the same time. These are fundamental language features.
Rust Book, "Understanding Ownership".
RAII: Resource Acquisition Is Initialization
Manage resources memory, files, network connections by tying them to the lifetime of an object. Automatic cleanup via Drop trait.
Rust Book, "Understanding Ownership".
Interior Mutability
Allow mutation of data even when there are immutable references. Use RefCell, Rc<RefCell<T>>, Cell types.
std::cell, std::sync::atomic⮳ documentation. The Rust Book, "Interior Mutability".
Represent the possibility of failure via Result or absence via Option. Result and Option are part of the prelude. Use match, unwrap, expect, and ? operator. Crates like anyhow⮳ and thiserror⮳ can help with error management.
The Rust Book, "Error Handling".
? Operator
Propagate errors concisely.
The Rust Book, "Error Handling".
From Trait
Define conversions between types with From, often used for error handling.
Altering an object's behavior when its internal state changes.
Often implemented directly using enums.
Enums are often used to represent states.
Strategy
Choosing an algorithm at runtime.
Often implemented directly using trait objects or enums.
Trait objects or enums are commonly used.
Template Method
Defining the skeleton of an algorithm and letting subclasses define specific steps.
Often implemented directly using traits
Traits are helpful for defining the template.
Visitor
Adding new operations to objects without changing their classes.
Often implemented directly using traits
Traits are usually used for visitor implementations.
Dependency Injection
Providing dependencies to components.
Dependency injection frameworks (shaku) exist, but it's often handled manually, especially in smaller projects. yew⮳ uses dependency injection for its component system.