Tags / 4 posts

#patterns

2025 1 post

  1. Alternative Blanket Implementations for a Single Rust Trait

    Rust rejects overlapping blanket impls, but an associated type plus marker structs lets each type pick one of two implementations.

2021 3 posts

  1. Builder with typestate in Rust

    Track required fields in the builder’s type parameters, so calling build() without an id or email fails to compile.

  2. Builder pattern in Rust

    A chained UserBuilder stands in for the keyword and optional arguments Rust lacks, but mandatory fields bring back positional arguments.

  3. Phantom Types in Rust 👻

    Share Add and Sub between Meter and Kilogram through one generic Unit<T> and PhantomData, without ever letting meters mix with kilograms.