Get the latest tech news

The weird of function-local types in Rust


Generate builders for everything!

The real code generated by#[bon::builder] is a bit more complex, it uses typestate pattern to catch all potential developer errors at compile time 🐱. Now imagine our builder macro is invoked for a struct defined inside of a local function scope: The compromise is not to use a child module, and obfuscate the private fields of the builder struct with leading__ and#[doc(hidden)] attributes to make it hard for the user to access them (even though not physically impossible).

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Function

Function

Photo of Rust

Rust

Photo of weird

weird

Related news:

News photo

I spent 2 years building my own game engine (Rust, WASM, WebGPU)

News photo

Build your own SQLite, Part 1: Listing tables

News photo

Spring-rs is a microservice framework in Rust inspired by Java's spring-boot