What is Nostr?
Jan David :ferris: /
npub1wpc…q8x5
2024-01-27 00:17:55

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

Author Public Key
npub1wpcd5eqzftpryqhwky7ehv0w4rct6c2tye4rv7fyp3s6uqegpu9sujq8x5