Index | About | Me | Jump to Menu Section

Notes on Rust For Rustaceans

Last modified: Wed May 11 2022 11:00:32 GMT+0000 (Coordinated Universal Time)

Foundations

Types

Alignment

Wide Pointers

The orphan rule

Designing Interfaces

Traits

Auto-traits

Object-safe (&dyn Trait)

Common traits for types

Wrapper types

Borrowed vs Owned

Fallible and Blocking Desctructors

Type system


struct Grounded;
struct Launched;

struct Rocket<Stage = Grounded> {
sage: std::marker::PhantomData<Stage>
// using phantomdata to guarantee that it is elimitend at compile time
}

impl Default for Rocket<Grounded> {}
impl Rocket<Grounded> {
pub fn launch(self)-> Rocket<Launched> {}
}

impl Rocket<Launched> {
pub fn accelerate(&mut self) { }
}

// everything that is generic and should be always available
// goes here
impl<Stage> for Rocket<Stage> {
pub fn color(&self) -> Color {}
}
// and so on...

Tests

Fuzzers

libfuzzer_sys::fuz_target!(|data: &[u8]| {
if let Ok(s) = std::str::from_utf8(data) {
let _ = url::Url::parse(s);
}
})

Property-based testing

Macros

Declarative Macros

Procedural Macros

Asynchronous Programming

enum Poll<T> {
Ready(T),
Pending,
}

Pin

Wakers

Blocking in async code

Unsafe Rust

Terms