You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the config crate together with its serde support. This seems to be problematic together with enums.
Reproducer
In this code, the inner test fails. However, the outer and inner_direct tests pass, so I think I'm not doing something completely silly.
use serde_derive::Deserialize;#[derive(Deserialize)]enumX{A,B,}#[derive(Deserialize)]structY{x:X,}#[derive(Deserialize,Default)]structInner{#[serde(default)]y:Vec<Y>,}#[derive(Deserialize,Default)]structOuter{#[serde(flatten)]y:Inner,}#[cfg(test)]mod tests {usesuper::*;use config::{Config,File,FileFormat};constTOML:&str = r#" [[y]] x = "A" [[y]] x = "B" "#;fncfg() -> Config{letmut config = Config::new();
config.merge(File::from_str(TOML,FileFormat::Toml)).unwrap();
config
}#[test]fninner(){cfg().try_into::<Inner>().unwrap();}#[test]fnouter(){cfg().try_into::<Outer>().unwrap();}#[test]fninner_direct(){
toml::from_str::<Inner>(TOML).unwrap();}}
Exact versions used, if they matter:
config: 0.9.1
serde: 1.0.80
serde-derive: 1.0.80
toml: 0.4.8
Guesses
To me it looks like the enum doesn't like to be deserialized from owned String, but doing it from &str is fine. And when going through the flattening, something on the way maybe goes from String to &str. But that's just a wild guess.
The text was updated successfully, but these errors were encountered:
If inner_direct passes but inner fails, it sounds like this is an issue with the config crate rather than with Serde. Please follow up with them about it. Thanks!
OK, but still, the fact that Inner and Outer acts different seems strange. Flattening one structure into another as its only field should IMO make them kind of equivalent?
Hello
I'm using the config crate together with its serde support. This seems to be problematic together with enums.
Reproducer
In this code, the
inner
test fails. However, theouter
andinner_direct
tests pass, so I think I'm not doing something completely silly.Exact versions used, if they matter:
Guesses
To me it looks like the enum doesn't like to be deserialized from owned
String
, but doing it from&str
is fine. And when going through the flattening, something on the way maybe goes fromString
to&str
. But that's just a wild guess.The text was updated successfully, but these errors were encountered: