-
-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flattened maps incorrectly (?) assumed to be maps #188
Comments
Could you please provide a complete reproducible example that I can compile and run? |
Yes, working on it. I'm also realizing that my issue might be a duplicate. |
I don't know any better than this, which doesn't compile: |
Yes, this looks like a duplicate of #98. Thank you for writing out a more complete example. |
One possible workaround is to use a tuple instead of a struct:
|
It's not a duplicate of #98, because this is specifically NOT a map. I would be a map if it weren't flattened, but it is. struct A {
#[serde(flatten)]
b: B,
z: i32,
}
struct B {
x: i32,
y: i32,
} Is exactly the same as struct A {
x: i32,
y: i32,
z: i32,
} when it comes to serialization, which is a valid and completely standard csv record. This means, the error is a false positive. The thing is, you don't HAVE to support hash maps, just structs is enough for basically all use cases. |
Serde still treats it as a map AIUI. Sorry, but Serde's |
What I kind of mean is this: The problem with flattening hashmaps is that the structure can change between records, making it a problem for writing the csv headers. If you instead just kind of assume the first record to be representative of the entire dataset, that would be a problem. With structs, that would not be a problem though, as you can just write the headers by using the first struct. I guess this also means the field itself can't be optional... I know it's annoying, but I think it would be better than nothing. in my opinion |
Imagine a data format like this:
These are nested structs, yes, but completely flattened, so they should be serializable to CSV. However, I get the following error:
Serialize: Error(Serialize("serializing maps is not supported, if you have a use case, please file an issue at https://github.com/BurntSushi/rust-csv"))
How can I work around this?
The text was updated successfully, but these errors were encountered: