This document is the course syllabus. It contains the grading and lecture course program.
- You have to solve all of the obligatory tasks to achieve a Satisfactory mark. Moreover, it's enough for a Satisfactory mark.
- Every task has a score X. After the deadline (usually 3 weeks) the score linearly lowers from X to X/2.
- There are 3 projects in the semester. Every project costs 1 point. After the project deadline (usually 4 weeks) the score linearly lowers from 1 to 1/2 for 2 weeks. Your maximum mark is determined by ceil value of these points:
- 0 points - Satisfactory(4) is maximum;
- 1 point - Good(7) is maximum;
- 2 points - Excellent(9) is maximum;
- 3 points - Excellent(10) is maximum.
- Let
project_max()be the function, which returns your maximum mark (4, 7, 9 or 10) depending on project points,my_score()the sum of your scores, andmax_score()the sum of all scores without deadline penalties. If all of the obligatory problems are solved, then your mark is:min(project_max(), max(3, round(10 * my_score() / max_score())))
-
Hello, Rust! Discussing the language. Comparison with C++. Basics of language.
- Why do we even need Rust? What problems does Rust solve? Where is Rust intended to be used? What companies are already using Rust?
- What do safe and unsafe mean. What do sound and unsound mean. What Rust considers safe. RustBelt formal model.
letandmutkeywords. Data typesi8...i128,u8...u128,isize,usize,f32,f64,bool. Literals.- Shadowing. Type inference.
askeyword for primitive casts. Non-transitivity of casting.- Compound types
arrayandtuple. Unit type(). T,&mut T,&T.- Remind of C++
std::reference_wrapper. - Functions.
returnkeyword. Expressions and statements. struct. Functional update.selfandSelf.implkeyword. Associated functions. Introduction to generics.enum.size_ofenumand discriminant.std::cmp::Ordering. Comparing with C++'senumandunion. Meaning of_.- Syntax of
if,while,for,loop. Namedbreak.if/whileandletsyntax sugar. match. Matching ranges. Multiple patterns. Binding modes. Destructuring.- Introduction to
Vecand part of its interface. Slice&[T]. panic!,unimplemented!,unreachable!,todo!,println!,assert!,assert_eq!.- Inhabited type
!. - Borrow checker and how not to give up at the beginning. The borrowing mechanism.
- Introduction to Rust ecosystem. VS Code plugins: official and rust-analyzer.
std::prelude. Basic usage ofcargoandrustc.
-
Standard library types and collections.
Vec,VecDequeand their interface.HashMap,HashSetand their interface. Asymptotics.BTreeMap,BTreeSetand their interface. Why can't B-Tree be used likestd::map.LinkedList,BinaryHeapand their interface.String. Random access. UTF-8.&strand reminder of C++string_view.charand meaning of Unicode scalar value.Resultand its interface.Option, its interface and compiler optimizations.- Heap allocations:
Box,Rc,Cowand their interface. Mention ofArc. - Why
Rcis immutable. - Module
std::cell. Interior mutability.Cell,RefCell. Reentrancy. std::memmodule and it's safe features:size_of,swap,replace,forget,drop.- Drop checker basics. Drop flags. Stability of drop order and reasons. Initialization order.
- Exotically sized types: ZST, DST, Empty. Containers, especially
Vec, whenTis ZST. NonNull,NonZero.print!,println!,eprint!,eprintln!,write!,writeln!and locking of IO stream.BufReaderandBufWriter. Their interface and reducing allocations count.
-
Traits. Functional programming features. Iterators.
- Traits. Return type polymorphism. Auto traits.
wherekeyword. Extension traits. - Basic library traits and their methods.
Default,Clone,Copy. Why aren't they derived by default? Ord,PartialOrd.Eq,PartialEq.Hash,Hasher.Drop,ManuallyDrop, and RAII. Relying on drop order.- Module
std::ops. TraitsAdd,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shrand their-Assignvariants.Not,Neg. - Traits
IndexandIndexMut. - Traits
DebugandDisplay.Formatter. The motivation of their design. TraitToString. Deref,DerefMut,Borrow.- Module
std::convert. TraitsFromandInto,TryFromandTryInto,AsRefandAsMut.identityfunction. - Compound types
arrayandtuple: what changes when their size is big. - Associated types and consts.
- Iterators. Laziness of iterators. Traits
Iterator,IntoIterator. Implementation of iterators instd. Iterators in Runtime. - API of iterators:
map,filter,fold,flattenand others. - Motivation of
Iteratortrait design. - Iterator invalidation in C++ and Rust.
- Iterators and vectorization. How to return iterator and closure from function:
implkeyword. - Module
std::iteruseful functions:from_fn,empty,once,repeat,repeat_with. - Traits
FromIterator,ExactSizeIterator,DoubleEndedIterator,Index,IndexMut. collect,flattenand their implementation.- Traits
FnOnce,Fn,FnMut. Closures. Capture clause.movekeyword. Variable rebinding in a separate scope.
- Traits. Return type polymorphism. Auto traits.
-
The Rust language package manager: Cargo. Error handling.
- Cargo. Crates and modules. Compilation unit. What's in a crate. Coherence.
- Cargo package structure. Cargo.lock, semantic versioning. Rustup. crates.io. Types of library crates.
use,mod,pub,super,crate. Wherepubdoesn't work.- Rust release cycle. Raw identifiers. Migrating to other edition.
- Error handling. Recoverable and unrecoverable errors. Panic and stack unwinding. Unwind safety.
Result<T, E>. Operator?and deprecatedtry!. Best practices of error handling. - Exception safety: minimal and maximal.
- Controlling panic.
catch_unwind,resume_unwind. Errortrait and its problems.- Basics of crates anyhow and thiserror.
-
Metaprogramming in Rust. Writing idiomatic code.
- Generics. Monomorphization. Static and dynamic polymorphism.
- Trait specialization.
- Reason why there's no generics partial specialization: ugly SFINAE consequences.
- Macro.
macro_rules!. Patterns,$crate. Identificators. Hygiene. Macros problems. Internal macro. - Basics of crate serde.
- Attributes.
non_exhaustive,deprecated. Macroenv!,option_env!,stringify!,include_str!. - Conditional compilation and crate cfg-if.
- Procedural macro.
derive,cfg,test.recursion_limitattribute for macros. - Basics of crate syn.
- Metaprogramming. Constant evaluation and
constkeyword. Const generics. Macro code generation. - Software design patterns: command, interpreter, newtype idiom, strategy, visitor, builder, fold.
- Software design antipattern: using deref polymorphysm.
- Tips of writing idiomatic code.
-
Virtual method table. Memory management and roots of system safety.
- Virtual method table. Fat pointer. Keyword
dyn. Dynamic dispatch. On-Stack Dynamic Dispatch. Dynamically sized types. - Module
std::any. TraitAny. - Type coercion and subtyping. Fully Qualified Syntax and when to use it.
- Object Safety. Generics in the virtual table.
Hashand inline. - How Rust manages memory: aliasing and "Aliasing XOR Mutability" rule (AXM).
- Borrow checker, affine type system.
- Lifetimes. Named references. Lifetime elision. Reborrowing.
- Unbounded
'staticlifetime: why do we need it and what's relationship to other lifetimes. - Higher-Rank Trait Bounds (HRTB). Variance.
refkeyword andmatch. Two phase borrows.- Drop checker. Connection of
PhantomDataand variance inference. - The dot operator and rules of auto dereference.
- Virtual method table. Fat pointer. Keyword
-
Working with filesystem. Roots of system safety: RustBelt research.
- Working with file system with module
std::fs. Comparing the design of Rust and Go. - GhostCell paper. Discussing the power of Rust type system and static checking.
- Aliasing model. Stacked borrows paper.
- Working with file system with module
-
Automatic Rust verification and support tools.
- Clippy and its lints.
- Rust analyzer.
- MIR interpreter Miri.
- Rudra static analyzer.
- Dynamic Symbolic Execution (DSE) tools: Rust verification tools (RVT), Cargo-KLEE.
- Model checkers: Rust Model Checker (RMC), SMACK
- Verification tools: Haybale, Stateright.
-
Parallel and concurrent computing in Rust.
- Rust memory model state. Orderings. Connection of memory safety and absence of data races.
- Module
std::thread. - Threads. Thread builder. Scope and static.
thread::scopedand its problems. Closure scope. Panic in closure scope. - Basics of crates rayon and crossbeam.
SendandSynctraits. Unsafe traits.Ordand undefined behavior.std::atomic:Atomicandfence.Arcand example of undefined behavior in unsafe code.Mutexand its poisoning.RwLock.Lazy.
-
Asynchronous Rust and networking.
- Motivation of asynchronous Rust design.
asyncandawait.- Stackless coroutines.
- Trait
Future. Building an executor. Pin,Unpinand their use cases.PhantomPinned.- Basics of different networking protocols from the ground up.
- Open Systems Interconnect model (OSI). Reminder of Ethernet, IP, UDP and TCP.
- Networking in Rust. Module
std::net.IpAddr.TcpListener,TcpStreamandUdpSocket. - Collecting metrics in Rust.
- Basics of crates tokio and loom.
-
Unsafe Rust. Representation of types in memory.
unsafekeyword. The contract between safe and unsafe code. What unsafe can do. When do we need unsafe. Problem: safemem::forget.mem::transmute.statickeyword.UnsafeCell. Pointers:*const T,*mut T.MaybeUninit. Compiler optimizations,Container<MaybeUninit<T>>>andContainer<T>.- Unsafe traits. Problems with safety on
BTreeMapand traitOrd. - WTF-8.
PathBufandPath. CStringandCStr.OsStringandOsStr.- Basics of crates
cbindgenandrust-bindgen. - Drop checker.
may_dangleattribute. - Implementation of
split_at_mut. - Discussing the implementation of
Vec. - Discussing the implementation of
ArcandMutex. - Module
std::alloc. Functionsalloc,alloc_zeroed,dealloc,Layout.GlobalAlloc. reallocin Rust andC++. Howmoveworks in Rust and C++. Move failures in C++. Discussing the moveit crate. Copying and cloning in Rust.- Leaking. Discussing the once_cell crate.
-
Rust and interacting with system and other languages.
- Sections
.data,.rodata,.bssand.text. Structure of heap and stack. Buffer overflow. - Representation of types in memory. Exotically sized type Extern.
enumin memory. Guaranties ofOption. Data layouts:C,transparent,u*,i*,packed,align(n). Field ordering. - Using C/C++ code from Rust. Using Rust code from C/C++.
- Rust ABI state.
- Tips for writing FFI.
- Signal handling.
- Calling to the kernel.
- The state of Rust in Linux kernel.
- Sections
-
Techniques of speeding up Rust.
- Module
core::archand SIMD.core::intrisicsand its usage in standard library. - Module
std::hint. - Link-time Optimization (LTO).
- Profile-guided Optimization (PGO).
- Rust profiling tools.
- Code inlining. Reasons and examples.
dynvsimplwhen both can be used.- Note about standard libraries
HashSetandHashMap. Siphash and alternatives. - Removing and reducing the number of heap allocations and reallocations. Profiling
mallocandfree. - Short vectors problem. Discussing the smallvec and arrayvec crates.
- Speeding up compilation and linking of big Rust projects.
- Module