-
Notifications
You must be signed in to change notification settings - Fork 131
Open
Labels
A-serdeArea: Serde integrationArea: Serde integrationC-enhancementCategory: Raise on the bar on expectationsCategory: Raise on the bar on expectations
Description
use serde::{Deserialize};
#[derive(Debug, Deserialize)]
struct S {
value: ExampleEnum,
}
#[derive(Debug, Deserialize)]
enum ExampleEnum {
Variant(Option<NestedEnum>),
}
#[derive(Debug, Deserialize)]
enum NestedEnum {
NestedVariant,
}
fn main() {
println!("{:?}", toml::from_str::<S>("value = { Variant = 'NestedVariant' }"));
println!("{:?}", toml::from_str::<S>("value = { Variant = 'None' }"));
println!("{:?}", toml::from_str::<S>("value = { Variant = '' }"));
println!("{:?}", toml::from_str::<S>("value = { Variant = {}}"));
println!("{:?}", toml::from_str::<S>("value = { Variant }"));
println!("{:?}", toml::from_str::<S>("value = 'Variant'"));
}
Currently this prints:
Ok(S { value: Variant(Some(NestedVariant)) })
Err(TomlError { message: "unknown variant `None`, expected `NestedVariant`", raw: Some("value = { Variant = 'None' }"), keys: ["value"], span: Some(20..26) })
Err(TomlError { message: "unknown variant ``, expected `NestedVariant`", raw: Some("value = { Variant = '' }"), keys: ["value"], span: Some(20..22) })
Err(TomlError { message: "wanted exactly 1 element, found 0 elements", raw: Some("value = { Variant = {}}"), keys: ["value"], span: Some(20..22) })
Err(TomlError { message: "expected `.`, `=`", raw: Some("value = { Variant }"), keys: [], span: Some(18..19) })
Err(TomlError { message: "invalid type: unit variant, expected newtype variant", raw: Some("value = 'Variant'"), keys: ["value"], span: Some(8..17) })
It would be nice if there were some way for this to work. toml-lang/toml#1025 indicates there is no null/none value, but it'd still be nice to be able to deserialize this somehow. Perhaps there's just no nice way to do that though...
Metadata
Metadata
Assignees
Labels
A-serdeArea: Serde integrationArea: Serde integrationC-enhancementCategory: Raise on the bar on expectationsCategory: Raise on the bar on expectations