This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 191
Can't deserialize into tuple struct #334
Labels
A-parsing
Deserialization
Comments
I think you need It looks like serde_json treats newtype_structs as "transparent" by default. toml should probably do the same. It looks to be specific to not working as a top-level table. |
luckysori
added a commit
to comit-network/comit-rs
that referenced
this issue
Nov 15, 2019
The solution could be simpler if toml-rs/toml-rs#334 were fixed. It would be even simpler if `serde` supported flattening enum variants, but it doesn't: serde-rs/serde#1402. Also: - Rename config file field from `allowed_foreign_origins` to `allowed_origins` since being under the CORS section already indicates that it refers to foreign origins.
luckysori
added a commit
to comit-network/comit-rs
that referenced
this issue
Nov 15, 2019
The solution could be simpler if toml-rs/toml-rs#334 were fixed. It would be even simpler if `serde` supported flattening enum variants, but it doesn't: serde-rs/serde#1402. Also: - Rename config file field from `allowed_foreign_origins` to `allowed_origins` since being under the CORS section already indicates that it refers to foreign origins.
A similar issue happened for a HashMap with tuple-struct keys. Adding use std::collections::HashMap;
use serde::Deserialize;
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Deserialize)]
// #[serde(transparent)]
struct S(String);
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Deserialize)]
struct T {
a: u64
}
fn main() {
let map: HashMap<S, T> = serde_json::from_str(r#"
{
"abc": {"a": 123},
"def": {"a": 456}
}
"#).unwrap();
println!("{:?}", map);
let map: HashMap<S, T> = toml::from_str(r#"
[abc]
a = 123
[def]
a = 456
"#).unwrap();
println!("{:?}", map);
}
|
Maintenance of this crate has moved to the https://github.com/toml-rs/toml repo. As a heads up, we plan to move Closing this out. If this is still a problem, feel free to recreate this issue in the new repo. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
It can't deserialize into the tuple struct:
message: "invalid type: map, expected tuple struct WrappedMap", key: []
These wrappers are quite common in rust and are supported by serde_json.
The text was updated successfully, but these errors were encountered: