Enter your book access code

The curriculum, drills, tutor, and interviewer mode are for readers of Ace the Rust Interview. The code is printed in the Preface (Companion site access).

Don’t have the book yet? The landing page stays open — purchase unlocks this gym.

beginner · order 44

Typestate for a connection

enum-typestate-01Related book chapters: 2, 7 (optional — this page is complete on its own)typestate

Slug: enum-typestate-01 · Paired reading: Chapters 2 and 7

Prompt

struct Conn<S>(PhantomData<S>) with zero-sized Disconnected / Connected markers. fn open() -> Conn<Disconnected>, fn connect(self) -> Conn<Connected>, fn send(self: &Conn<Connected>, msg: &str) -> String (e.g. prefix sent:).