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.
let
andmut
keywords. Data typesi8...i128
,u8...u128
,isize
,usize
,f32
,f64
,bool
. Literals.- Shadowing. Type inference.
as
keyword for primitive casts. Non-transitivity of casting.- Compound types
array
andtuple
. Unit type()
. T
,&mut T
,&T
.- Remind of C++
std::reference_wrapper
. - Functions.
return
keyword. Expressions and statements. struct
. Functional update.self
andSelf
.impl
keyword. Associated functions. Introduction to generics.enum
.size_of
enum
and discriminant.std::cmp::Ordering
. Comparing with C++'senum
andunion
. Meaning of_
.- Syntax of
if
,while
,for
,loop
. Namedbreak
.if
/while
andlet
syntax sugar. match
. Matching ranges. Multiple patterns. Binding modes. Destructuring.- Introduction to
Vec
and 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 ofcargo
andrustc
.
-
Standard library types and collections.
Vec
,VecDeque
and their interface.HashMap
,HashSet
and their interface. Asymptotics.BTreeMap
,BTreeSet
and their interface. Why can't B-Tree be used likestd::map
.LinkedList
,BinaryHeap
and their interface.String
. Random access. UTF-8.&str
and reminder of C++string_view
.char
and meaning of Unicode scalar value.Result
and its interface.Option
, its interface and compiler optimizations.- Heap allocations:
Box
,Rc
,Cow
and their interface. Mention ofArc
. - Why
Rc
is immutable. - Module
std::cell
. Interior mutability.Cell
,RefCell
. Reentrancy. std::mem
module 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
, whenT
is ZST. NonNull
,NonZero
.print!
,println!
,eprint!
,eprintln!
,write!
,writeln!
and locking of IO stream.BufReader
andBufWriter
. Their interface and reducing allocations count.
-
Traits. Functional programming features. Iterators.
- Traits. Return type polymorphism. Auto traits.
where
keyword. 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
,Shr
and their-Assign
variants.Not
,Neg
. - Traits
Index
andIndexMut
. - Traits
Debug
andDisplay
.Formatter
. The motivation of their design. TraitToString
. Deref
,DerefMut
,Borrow
.- Module
std::convert
. TraitsFrom
andInto
,TryFrom
andTryInto
,AsRef
andAsMut
.identity
function. - Compound types
array
andtuple
: 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
,flatten
and others. - Motivation of
Iterator
trait design. - Iterator invalidation in C++ and Rust.
- Iterators and vectorization. How to return iterator and closure from function:
impl
keyword. - Module
std::iter
useful functions:from_fn
,empty
,once
,repeat
,repeat_with
. - Traits
FromIterator
,ExactSizeIterator
,DoubleEndedIterator
,Index
,IndexMut
. collect
,flatten
and their implementation.- Traits
FnOnce
,Fn
,FnMut
. Closures. Capture clause.move
keyword. 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
. Wherepub
doesn'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
. Error
trait 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_limit
attribute for macros. - Basics of crate syn.
- Metaprogramming. Constant evaluation and
const
keyword. 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.
Hash
and inline. - How Rust manages memory: aliasing and "Aliasing XOR Mutability" rule (AXM).
- Borrow checker, affine type system.
- Lifetimes. Named references. Lifetime elision. Reborrowing.
- Unbounded
'static
lifetime: why do we need it and what's relationship to other lifetimes. - Higher-Rank Trait Bounds (HRTB). Variance.
ref
keyword andmatch
. Two phase borrows.- Drop checker. Connection of
PhantomData
and 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::scoped
and its problems. Closure scope. Panic in closure scope. - Basics of crates rayon and crossbeam.
Send
andSync
traits. Unsafe traits.Ord
and undefined behavior.std::atomic
:Atomic
andfence
.Arc
and example of undefined behavior in unsafe code.Mutex
and its poisoning.RwLock
.Lazy
.
-
Asynchronous Rust and networking.
- Motivation of asynchronous Rust design.
async
andawait
.- Stackless coroutines.
- Trait
Future
. Building an executor. Pin
,Unpin
and 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
,TcpStream
andUdpSocket
. - Collecting metrics in Rust.
- Basics of crates tokio and loom.
-
Unsafe Rust. Representation of types in memory.
unsafe
keyword. The contract between safe and unsafe code. What unsafe can do. When do we need unsafe. Problem: safemem::forget
.mem::transmute
.static
keyword.UnsafeCell
. Pointers:*const T
,*mut T
.MaybeUninit
. Compiler optimizations,Container<MaybeUninit<T>>>
andContainer<T>
.- Unsafe traits. Problems with safety on
BTreeMap
and traitOrd
. - WTF-8.
PathBuf
andPath
. CString
andCStr
.OsString
andOsStr
.- Basics of crates
cbindgen
andrust-bindgen
. - Drop checker.
may_dangle
attribute. - Implementation of
split_at_mut
. - Discussing the implementation of
Vec
. - Discussing the implementation of
Arc
andMutex
. - Module
std::alloc
. Functionsalloc
,alloc_zeroed
,dealloc
,Layout
.GlobalAlloc
. realloc
in Rust andC++
. Howmove
works 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
,.bss
and.text
. Structure of heap and stack. Buffer overflow. - Representation of types in memory. Exotically sized type Extern.
enum
in 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::arch
and SIMD.core::intrisics
and its usage in standard library. - Module
std::hint
. - Link-time Optimization (LTO).
- Profile-guided Optimization (PGO).
- Rust profiling tools.
- Code inlining. Reasons and examples.
dyn
vsimpl
when both can be used.- Note about standard libraries
HashSet
andHashMap
. Siphash and alternatives. - Removing and reducing the number of heap allocations and reallocations. Profiling
malloc
andfree
. - Short vectors problem. Discussing the smallvec and arrayvec crates.
- Speeding up compilation and linking of big Rust projects.
- Module