-
-
Notifications
You must be signed in to change notification settings - Fork 854
Closed
Description
EDIT After thinking about it some more, I feel it would be better to improve this error message rather than add API surface area. #1544 gets close, but I believe those errors are still too opaque for Cargo's purposes, and it's hidden behind a flag. Anyway, my original post:
I have an untagged union:
#[derive(Serialize, Deserialize)]
#[serde(untagged)]
enum MyEnum {
Foo(Vec<String>),
Bar(usize)
}
If all variants fail, you get this error message:
Line 1648 in 9f331cc
"data did not match any variant of untagged enum {}", |
Is there a good way to customize the error message but keep the default #[derive(Deserialize)]
implementation? Perhaps a new attribute?:
#[serde(untagged, expecting = "a number or a list of strings")]
enum MyEnum {
...
}
Advantages:
- You don't have to reimplement
Deserialize
- Concise
Disadvantages
- How common is this use-case? We have to do this a couple of times within Cargo.
- Is there a better solution I am overlooking?
Mingun and AlexTMjugador
Metadata
Metadata
Assignees
Labels
No labels