toml icon indicating copy to clipboard operation
toml copied to clipboard

Deserializing tupled enum error

Open maciekglowka opened this issue 2 years ago • 0 comments

Hi, I can't seem to deserialize an enum containing a tuple-like value. ( Heal variant below).

#[derive(Clone, Copy, Debug, Deserialize)]
pub enum ActionKind {
    Descend,
    Heal(u32)
}

#[derive(Component, Deserialize)]
pub struct Interactive {
    pub kind: ActionKind
}

I would guess that the proper input here would be something in the shape of:

Interactive = { kind = { Heal = 2 } }

but I keep getting an error: "invalid type: unit variant, expected string only", key: []

A bit of Googling made me think that there might be some bug with that, but maybe my input syntax is wrong (although tried many different ones)

Strangely if I try to parse it from string, it works

let i: Interactive = toml::from_str(r#"kind = { Heal = 2 } "#)?;

However if I parse the raw data beforehand (a bigger structure) and the parser is then fed with the toml::Value - then I get an error (as above).

That's what the debug shows for the value: Table({"kind": Table({"Heal": Integer(2)})}

That's the parsing line:

data.try_into::<Interactive>()?

maciekglowka avatar Dec 27 '22 15:12 maciekglowka