External Publication
Visit Post

Subset enums

Rust Internals [Unofficial] March 3, 2026
Source

DidingasLushis:

would my example be re-worked to be like:

I would guess something like

type MyErrorSubset = MyError is (MyError::NotFound | MyError::PermissionDenied);

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

It's possible it'll have to be

struct MyErrorSubset(MyError is (MyError::NotFound | MyError::PermissionDenied));

in order for Result<T, MyErrorSubset> to actually take layout advantage.

(This kind of thing is one of the reasons it'll take a while to be stable.)

Discussion in the ATmosphere

Loading comments...