External Publication
Visit Post

F-pattern_types : Subsets enums using as

Rust Internals [Unofficial] March 3, 2026
Source

scottmcm:

The hard question is whether Result<T, MyErrorSubset> can actually be any smaller if it's defined that way.

In my opinion, the main benefit to pattern types is in exhaustiveness checking in e.g. match constructs and other static guarantees, though it'll be a nice extra if e.g. Result<NonZeroU32, MyError is MyError::NotFound> gets optimized to the same size as a u32. An initial implementation which handles the language semantics, but leaving open optimization opportunities for later, would be good enough for me to be happy.

Discussion in the ATmosphere

Loading comments...