Jan David :ferris: on Nostr: Hot take: Public interfaces in #rustlang should never expose primitive types such as ...
Hot take: Public interfaces in #rustlang should never expose primitive types such as strings or numbers. Instead, primitive types should be wrapped into newtypes.
Being explicit about the type of a field can prevent so many bugs, and newtypes are zero-cost abstractions without a runtime penalty.
I've really come to appreciate this pattern in my own projects, and have been hacking on a crate that make it very convenient to generate these types.
https://crates.io/crates/typed-fields
Being explicit about the type of a field can prevent so many bugs, and newtypes are zero-cost abstractions without a runtime penalty.
I've really come to appreciate this pattern in my own projects, and have been hacking on a crate that make it very convenient to generate these types.
https://crates.io/crates/typed-fields