It depends if there are uses where the empty variant is invalid or not
-
-
-
In this case the empty variant would be valid. So I'm guessing encoding None as a member would work best for that?
- 2 more replies
New conversation -
-
-
the first one, then you get .map for free
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I'd need to know the reason why it's empty. If it's an inescapable fact of the business logic, which means it's always a possibility then in the enum, otherwise if it's due to missing data or an occasionally optional input outside via an optional/maybe.
-
Also are there semantics that can be conveyed beyond “empty”? Encoding the “why” of empty-ness.
End of conversation
New conversation -
-
-
I've gone back and forth on this in sled's API over the years. Now I tend to nest familiar Result and Option types rather than combining them into a single new type when getting a value that might not exist using io. But empty variants are great as markers, state machines etc...
-
Users expect to use Options for things that are optional. But if you're creating a new concept, go with empty variants.
- 1 more reply
New conversation -
-
-
Interesting question! I think I'd go with the Option first, because it let's me keep the handling of emptiness outside of the methods on the enum. For a neater API you can try to `impl ExtTrait for Option<MyEnum> {}` but it only goes so far.
-
This Tweet is unavailable.
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.