Skip to content
0:00 / 0:00

#typestate-pattern#generics#zero-sized-types

Improve your Rust APIs with the type state pattern

Let's Get Rusty

177K subscribers • 8 videos on Hallway

YouTube

Intermediate. Assumes working knowledge.

122K views3 years ago3 recommendations

Programming languagesSoftware designRustAPI designDesign patterns

How to design misuse-resistant Rust APIs using generics, zero-sized types, and the typestate pattern.

Join our Rust Live Accelerator waitlist (free Rust Job-Ready Roadmap inside): letsgetrusty.com/join Let’s Get Rusty is the #1 Rust education & career development platform for engineers who want real-world skills and results. We combine a structured curriculum, industry-grade projects, expert review and feedback, and our Rust recruiter network — to help you master Rust and get hired. · Today I'm teaching you how to build Rust APIs that are impossible to misuse by taking advantage of generics and zero-sized types! FREE Rust Cheat Sheet: letsgetrusty.com/cheatsheet Code: github.com/letsgetrusty/generics_and_zero_sized_types Chapters: Intro Example overview First solution Second solution Third solution Outro

Why it's here

3 people recommend this

What people say. Recommended as a helpful guide for implementing the typestate pattern to enforce invariants at compile time.

u/nima2613in r/rust • Recommends

On “How to properly deal with invariants”

You can try type state pattern: link to this video

u/pfharlockkin r/rust • Recommends

On “The peer pressure to learn rust.”

…amount of bugs (you don't realize how many until they simply aren't possible any more). Lastly I'll bring up the type state pattern... This is where you encode state machines into the type system in a way that can be checked/verified at compile time... (In other words you can make a state machine where an invalid state simply won't compile)... link to this video…

u/Jonasksin r/rust • Recommends

On “Some questions from a noob Rustacean”

I’m probably not qualified enough to give good tips, but this video seems like a relevant one? The third solution?