-
-
Notifications
You must be signed in to change notification settings - Fork 779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Serialize/Deserialize for Infallible #2073
Comments
For types with only one possible value, a unit struct seems more appropriate than something involving #[derive(Serialize)]
struct Null; |
Implementing Imagine enum like this. #[derive(Serialize, Deserialize)]
enum Foo<T> {
A,
B,
C(T),
} it may be desirable to serialize and deserialize #[derive(Serialize, Deserialize)]
enum Never {} and use |
I'm working on a system that accepts user state in the form of a |
Suppose I have an API where a value can only be
null
. In Rust, the semantic way to representnull
is viaOption::<T>::None
, but it's unclear whatT
should be because the value can never beSome(value)
, onlyNone
.I think it would be useful to be able to use
Option<Infallible>
(and possiblyOption<!>
) to represent these values. One way to do this is to implementSerialize
directly forInfallible
:Since an instance of
Infallible
should theoretically never be serialized, this would allowOption<Infallible>
to serialize asNone
.It would also be nice to be able to deserialize
Option<Infallible>
:As a temporary solution, it's possible to define an empty enum and implement these traits on it.
The text was updated successfully, but these errors were encountered: