from Hacker News

Show HN: Zero-overhead compile-time builder pattern for Rust

by cat-whisperer on 1/8/25, 10:33 PM with 1 comments

  • by cat-whisperer on 1/9/25, 12:18 AM

    We've all used builder patterns. And though they're elegant, debugging them can be frustrating. I discovered this while working with a large struct – missing a field only surfaced during runtime, which wasn't ideal. That got me thinking: since we're using Rust, why not leverage the compiler to catch these issues for us?

    That's why I created buco. It's a simple yet powerful crate that gives you all the benefits of the builder pattern, but moves all the checks to compile time. If you miss a field, the compiler won't even let you call the build method.