News for hackers. Stuff that matters.
Re:FOSDEM 2025: The state of Rust trying to catch up with Ad... by eslaught on Monday February 10, 2025 @02:20PM (#43004099)
Maybe not fully ergonomic yet, but this exists today (at least for max):

https://docs.rs/nonmax/latest/nonmax/

If you're really attached to it being min you'd have to copy that library.

Edit to add: we actually use these in one of my main Rust codes; they're useful, but I'm not sure they're so useful I'd want them built into the language.

Re:FOSDEM 2025: The state of Rust trying to catch up with Ad... by tialaramex on Monday February 10, 2025 @02:37PM (#43004292)
Yeah, the XOR trick†. It's very affordable on modern hardware (your CPU can cheerfully XOR two registers while doing other things, barely measurable) but it's more the principle of the thing. Maybe I should just put up with the XOR trick and stop thinking about Pattern Types but I don't think I'll be able to.

† Just in case you've never looked inside those types, they have a constant value and when you want a NonFoo you just take a NonZero and you XOR it with that constant, in other respects they work the same way as any other wrapper type. This is one reason the NonZero types exist, they make the XOR trick very easy to do.