Giter Site home page Giter Site logo

Comments (3)

BurntSushi avatar BurntSushi commented on June 3, 2024

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.

BurntSushi avatar BurntSushi commented on June 3, 2024

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.

wjwei-handsome avatar wjwei-handsome commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.