Skip to content

Serialize -> Deserialize of struct crate a SpannedError #456

@LuckyTurtleDev

Description

@LuckyTurtleDev

An simple Serializing and BackDeserialize does creat an error.
Did I do something wrong?

#[derive(Clone, Debug, Decode, Default, Deserialize, Encode, PartialEq, Serialize)]
#[serde(deny_unknown_fields)] 
pub struct AvailableCards {
	pub left: u8,
	pub right: u8
}

#[derive(Clone, Debug, Deserialize, Serialize)]
struct MapProperties{
	#[serde(flatten)]
	cards: AvailableCards,
}


let map_properties = MapProperties{cards: AvailableCards{
	..Default::default()
}};
let map_properties = ron::to_string(&map_properties).unwrap();
println!("{map_properties}");
let map_properties: MapProperties = ron::from_str(&map_properties).unwrap();  //line 145
{"left":0,"right":0}
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SpannedError { code: ExpectedIdentifier, position: Position { line: 1, col: 2 } }', /home/lukas/git/m3/map/src/lib.rs:145:76
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Some with serde_json works:

let map_properties = MapProperties{cards: AvailableCards{
	..Default::default()
}};
let map_properties = serde_json::to_string(&map_properties).unwrap();
println!("{map_properties}");
let map_properties: MapProperties = serde_json::from_str(&map_properties).unwrap();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions