Programming in Rust
Course objectives
Delegates will learn:
- how to create projects and manage dependencies using the Cargo manager
- language syntax, object-oriented model (traits) and elements of functional programming
- language mechanisms that significantly improve code security, such as variable lifetime control, memory management philosophy, and thread safety
Course syllabus
Introducing Rust
- Rust toolchain: compiler, debugger, Cargo
- Project structure and dependency management
Common programming concepts
- Basic data types
- Constants and variables
- Control flow
- if statements and expressions
- loops
- Functions
- Arrays, slices and vectors
- Tuples
Structs
- Named-field structs
- Tuple-like structs
- Unit-like structs
- Struct layout
- Defining methods with
impl
- Generic structs
- Deriving common traits for struct types
Enums and Pattern Matching
- Enums
- Matching using patterns
- Refutable Patterns with
if let
andwhile let
Ownership & Borrow
- Ownership
- Moves and copy
- References
- Borrowing variables
- Sharing vs. Mutating
- Reference safety in Rust
- Lifetime annotations
Memory management
- Resource management in Rust:
Drop
trait - The stack and the heap
- Smart Pointers in Rust
Box
,Rc
andArc
- Interior mutablility:
Cell<T>
andRefCell<T>
Error handling
- Panic - unwinding & aborting
- Error handling in Rust
- Catching & propagating errors
- Handling errors in
main()
- Declaring a custom error type
OOP in Rust
- Defining structures
- Implementing functions for structures
- Traits
- Idioms and OOP design patterns
Functional programming
- Anonymous functions and closures
- Idioms and FP design patterns
Managing projects
- Crates
- Modules and packages
- Cargo package manager
Multithreading
- Creating threads - Fork-Join Parallelism
- Sharing data across threads
- Mutexes in Rust
- Message passing using channels
Testing
- Writing and running unit tests
- Organizing tests in Rust project
Prerequisites
Basic knowledge of another imperative programming language.