Comments (3)
I spent about 10 minutes looking into this, and I can't make heads or tails of it myself. I note, for example, that this works:
#[derive(Serialize, Debug, Deserialize)]
struct Foo {
a: String,
b: String,
c: String,
d: String,
}
So to me, the serde(flatten)
example you have should also work since it should be equivalent to the above.
If you look at the issues on this tracker, a lot of them are about Serde. And of those issues, a lot of thoses are about serde(flatten)
. It is really one of the worst things about maintaining this library.
from rust-csv.
I also note that this works:
use serde::{Serialize, Deserialize};
#[derive(Serialize, Debug, Deserialize)]
struct Foo {
#[serde(flatten)]
bar1: Bar,
#[serde(flatten)]
bar2: Bar2,
}
#[derive(Serialize, Debug, Deserialize)]
struct Bar {
a: String,
b: String,
}
#[derive(Serialize, Debug, Deserialize)]
struct Bar2 {
c: String,
d: String,
}
fn main() {
let csv_ = "a,b,c,d\nw,x,y,z\nq,w,e,r\n";
let f :Foo = csv::ReaderBuilder::new()
.from_reader(csv_.as_bytes())
.deserialize().next().unwrap().unwrap();
println!("{:?}", f)
}
So there is likely something funny going on with the support for Serde without header names. Since you're duplicating a struct here, I suspect what you want to do is either not possible or requires work on the Serde deserializer in this crate to make it work. (And I'm not even sure the latter is possible.)
from rust-csv.
Thank you very much for your attention.
I also think the error comes from serde
,
I fully understand and I will try your suggestion.
Best wishes!
from rust-csv.
Related Issues (20)
- Use `#[non_exhaustive]` tag instead of manually `__Nonexhaustive` variant
- Program crashes caused by inappropriate parameter sizes. HOT 1
- Deserialize a field to an empty Vec<>
- Disable line terminator config HOT 5
- `write_byte_record` and `write_field` does not mix well and this is not properly documented. HOT 1
- Feature: Manually add headers to new CSV, using proposed csv::Writer.push_header() function HOT 2
- Space after delimiter messes with quoting HOT 5
- How to writing column? HOT 1
- Handling (serialization) of nested containers HOT 8
- Add Support for serde_transcode::transcode HOT 2
- Deserializing a String field inside a flattende struct fails if the field contains a valid integer HOT 4
- Feature request: please add `invalid_result` deserializer HOT 7
- Can the separator in CSV format support the char type? HOT 1
- Header Implementations "Content-Disposition". HOT 2
- How to serialize to a byte buffer HOT 16
- Automatically add an index number to headers that contain duplicate fields. HOT 2
- Error During the Deserialization of `String` Fields from Nested `struct`s HOT 4
- unexpected behavior (bug?) when using serde untagged with an enum to deserialize csv data HOT 1
- Serializing `None` vs serializing empty string HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-csv.