A daily Rust tip series for developers coming from other languages (Java, Python, C++, JS/TS, C#, Go, Kotlin). The tips are listed in order below. Some have a follow-up discussion (reader questions and answers) in a companion file next to the tip.
- Macros Aren't As Bad As Other Languages Make Them To Be!
- macro_rules! - The Dark Arts of Token Matching!
- Banning Null
- Reaching the Point of No return!
- Variables That... Don't Vary
- Shadowing, Reusing Variable Names on Purpose!
const-- Values the Compiler Knows Before Your Program Even Starts- No Free Lunches, No Free Defaults
- Structs, or "Classes Without the Drama"
impl-- Where Your Structs Learn New Tricks- Enums -- More Than Just a List of Labels
match-- The Switch Statement That Actually Worksif/elseReturns a Value, So Ternary Can Retire- Loops, Three Ways
- Iterators, Part 1
- Exceptions, the Feature You'll Wish Your Language Didn't Have
- Iterators, Part 2
- Ownership, the Rule That Replaces the Garbage Collector
- Move Semantics, or Why Assignment Looks Different in Rust
- Borrowing, or Reading Without Owning · discussion
- Mutable Borrowing and the XOR Rule
- Lifetimes, or Why a Reference Cannot Outlive Its Referent · discussion
- Strings, or Why There Are Two of Them · discussion
- Method Receivers, or Why Your Methods Have Three Different
selfs - Slices, or Borrowing Just Part of Something
- Derive Macros, or How to Make the Compiler Write Your Boilerplate · discussion
- Traits, the Shape Your Types Can Promise · discussion
- Box, Heap Allocation You Can See · discussion
- Rc, Sharing Without Copying
- RefCell, Borrowing at Runtime
- Closures, the Anonymous Functions That Borrow
- Cow, Borrow Or Own, Decide Later · discussion
- Arc and Mutex, the Thread-Safe Versions · discussion
- Send and Sync, the Marker Traits Behind Thread Safety
- Panicking, Drop Everything and Run · discussion
- Generics and Trait Bounds, Writing Code for All Types · discussion
- dyn Trait, Runtime Polymorphism · discussion
- Associated Types and Default Methods, or How Iterator Really Works
- From and Into, the Conversion Pair · discussion
- Modules, How Rust Splits a Program Into Pieces
- Cargo, Crates, and Packages · discussion
- Dependencies, Cargo.toml, and the Crates Ecosystem · discussion
- The Standard Library, and What Is Not In It
- Editions, Releases, and Who Keeps the Promise · discussion
- What
cargo buildActually Does - Build Profiles, or Why You Want
--releaseBefore Benchmarking