Comment

Comment by Arnavion

>I wonder, why is it NonZeroU8, NonZeroU16, etc instead of something like NonZero<u8>, NonZero<u16>, etc?

The RFC covers this. https://github.com/rust-lang/rfcs/blob/master/text/2307-conc... Also see the RFC discussion at https://github.com/rust-lang/rfcs/pull/2307

Basically the generic NonZero already existed, but it's hard to express safely when used with arbitrary user types.

>In theory, in the future, when Rust supports constants as template arguments, one might even add a const argument, the value that should be used as "null". E.g. if my u8 never reaches 255, I could use something like Never<u8, 255>.

This requires const generics, so it could happen when they're implemented. (This is also mentioned in the RFC discussion.)

parent Arnavion 8 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton