toml icon indicating copy to clipboard operation
toml copied to clipboard

Error when serializing enum with struct

Open Shatur opened this issue 2 years ago • 2 comments

Consider the following code:

use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
struct Foo {
    bar: Baz,
}

#[derive(Deserialize, Serialize)]
enum Baz {
    Test(Test)
}

#[derive(Deserialize, Serialize)]
struct Test {
    name: String,
}

fn main() {
    let string = std::fs::read_to_string("test.toml").unwrap();
    let foo: Foo = toml_edit::de::from_str(&string).unwrap();
    toml_edit::ser::to_string(&foo).unwrap();
}

with the following test.toml:

bar = { Test = { name = "asdf" } }

Deserialization works, but serialization panics with

called `Result::unwrap()` on an `Err` value: Error { kind: UnsupportedType }

Shatur avatar Aug 15 '22 09:08 Shatur

I wonder if #321 is related

epage avatar Jan 18 '23 17:01 epage

#405 might also be related

epage avatar Jan 18 '23 17:01 epage