ron: Struct flattening not working

I’m trying to use Serde’s struct flattening functionality with RON, using the Rust code below:

#[derive(Deserialize, Serialize)]
struct Main {
    #[serde(flatten)]
    required: Required,
    #[serde(flatten)]
    optional: Optional,

    some_other_field: u32,
}

#[derive(Deserialize, Serialize)]
struct Required {
    first: u32,
    second: u32,
}

#[derive(Deserialize, Serialize)]
struct Optional {
    third: Option<u32>,
}

This is the RON that I am attempting to deserialize:

Main(
    first: 1,
    second: 2,
    third: Some(3),
    some_other_field: 1337,
)

When I try to deserialize the target struct from RON, I get the following error:

thread 'example::test' panicked at 'called `Result::unwrap()` on an `Err` value: Parser(ExpectedMap, Position { col: 9, line: 2 })', libcore/result.rs:945:5        
note: Run with `RUST_BACKTRACE=1` for a backtrace.

On the other hand, deserializing from the following TOML string works as intended:

first = 1
second = 2
third = 3
some_other_field = 4

Any indication on what might be going wrong?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 23 (15 by maintainers)

Commits related to this issue

Most upvoted comments

This bug makes it impossible to use palette crate’s types with ron, as it uses struct flattening everywhere.