Rust for C# Programmers: Complete Training Guide
A comprehensive guide to learning Rust for developers with C# experience. This guide covers everything from basic syntax to advanced patterns, focusing on the conceptual shifts and practical differences between the two languages.
Course Overview
- The case for Rust — Why Rust matters for C# developers: performance, safety, and correctness
- Getting started — Installation, tooling, and your first program
- Basic building blocks — Types, variables, control flow
- Data structures — Arrays, tuples, structs, collections
- Pattern matching and enums — Algebraic data types and exhaustive matching
- Ownership and borrowing — Rust’s memory management model
- Modules and crates — Code organization and dependencies
- Error handling — Result-based error propagation
- Traits and generics — Rust’s type system
- Closures and iterators — Functional programming patterns
- Concurrency — Fearless concurrency with type-system guarantees, async/await deep dive
- Unsafe Rust and FFI — When and how to go beyond safe Rust
- Migration patterns — Real-world C# to Rust patterns and incremental adoption
- Best practices — Idiomatic Rust for C# developers
Self-Study Guide
This material works both as an instructor-led course and for self-study. If you’re working through it on your own, here’s how to get the most out of it.
Pacing recommendations:
| Chapters | Topic | Suggested Time | Checkpoint |
|---|---|---|---|
| 1–4 | Setup, types, control flow | 1 day | You can write a CLI temperature converter in Rust |
| 5–6 | Data structures, enums, pattern matching | 1–2 days | You can define an enum with data and match exhaustively on it |
| 7 | Ownership and borrowing | 1–2 days | You can explain why let s2 = s1 invalidates s1 |
| 8–9 | Modules, error handling | 1 day | You can create a multi-file project that propagates errors with ? |
| 10–12 | Traits, generics, closures, iterators | 1–2 days | You can translate a LINQ chain to Rust iterators |
| 13 | Concurrency and async | 1 day | You can write a thread-safe counter with Arc<Mutex<T>> |
| 14 | Unsafe Rust, FFI, testing | 1 day | You can call a Rust function from C# via P/Invoke |
| 15–16 | Migration, best practices, tooling | At your own pace | Reference material — consult as you write real code |
| 17 | Capstone project | 1–2 days | You have a working CLI tool that fetches weather data |
How to use the exercises:
- Chapters include hands-on exercises in collapsible
<details>blocks with solutions - Always try the exercise before expanding the solution. Struggling with the borrow checker is part of learning — the compiler’s error messages are your teacher
- If you’re stuck for more than 15 minutes, expand the solution, study it, then close it and try again from scratch
- The Rust Playground lets you run code without a local install
Difficulty indicators:
- 🟢 Beginner — Direct translation from C# concepts
- 🟡 Intermediate — Requires understanding ownership or traits
- 🔴 Advanced — Lifetimes, async internals, or unsafe code
When you hit a wall:
- Read the compiler error message carefully — Rust’s errors are exceptionally helpful
- Re-read the relevant section; concepts like ownership (ch7) often click on the second pass
- The Rust standard library docs are excellent — search for any type or method
- For deeper async patterns, see the companion Async Rust Training
Table of Contents
Part I — Foundations
1. Introduction and Motivation 🟢
- The Case for Rust for C# Developers
- Common C# Pain Points That Rust Addresses
- When to Choose Rust Over C#
- Language Philosophy Comparison
- Quick Reference: Rust vs C#
2. Getting Started 🟢
- Installation and Setup
- Your First Rust Program
- Cargo vs NuGet/MSBuild
- Reading Input and CLI Arguments
- Essential Rust Keywords (optional reference — consult as needed)
3. Built-in Types and Variables 🟢
- Variables and Mutability
- Primitive Types Comparison
- String Types: String vs &str
- Printing and String Formatting
- Type Casting and Conversions
- True Immutability vs Record Illusions
4. Control Flow 🟢
- Functions vs Methods
- Expression vs Statement (Important!)
- Conditional Statements
- Loops and Iteration
5. Data Structures and Collections 🟢
- Tuples and Destructuring
- Arrays and Slices
- Structs vs Classes
- Constructor Patterns
Vec<T>vsList<T>- HashMap vs Dictionary
6. Enums and Pattern Matching 🟡
- Algebraic Data Types vs C# Unions
- Exhaustive Pattern Matching
Option<T>for Null Safety- Guards and Advanced Patterns
7. Ownership and Borrowing 🟡
- Understanding Ownership
- Move Semantics vs Reference Semantics
- Borrowing and References
- Memory Safety Deep Dive
- Lifetimes Deep Dive 🔴
- Smart Pointers, Drop, and Deref 🔴
8. Crates and Modules 🟢
9. Error Handling 🟡
- Exceptions vs
Result<T, E> - The ? Operator
- Custom Error Types
- Crate-Level Error Types and Result Aliases
- Error Recovery Patterns
10. Traits and Generics 🟡
- Traits vs Interfaces
- Inheritance vs Composition
- Generic Constraints: where vs trait bounds
- Common Standard Library Traits
11. From and Into Traits 🟡
12. Closures and Iterators 🟡
Part II — Concurrency & Systems
13. Concurrency 🔴
- Thread Safety: Convention vs Type System Guarantees
- async/await: C# Task vs Rust Future
- Cancellation Patterns
- Pin and tokio::spawn
14. Unsafe Rust, FFI, and Testing 🟡
- When and Why to Use Unsafe
- Interop with C# via FFI
- Testing in Rust vs C#
- Property Testing and Mocking
Part III — Migration & Best Practices
15. Migration Patterns and Case Studies 🟡
16. Best Practices and Reference 🟡
- Idiomatic Rust for C# Developers
- Performance Comparison: Managed vs Native
- Common Pitfalls and Solutions
- Learning Path and Resources
- Rust Tooling Ecosystem
Capstone
17. Capstone Project 🟡
- Build a CLI Weather Tool — combines structs, traits, error handling, async, modules, serde, and testing into a working application