Skip to content
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

Question about deserializing with serde::de::DeserializeSeed #258

Open
sqwishy opened this issue Dec 29, 2021 · 1 comment
Open

Question about deserializing with serde::de::DeserializeSeed #258

sqwishy opened this issue Dec 29, 2021 · 1 comment

Comments

@sqwishy
Copy link

sqwishy commented Dec 29, 2021

What I'm trying to do is deserialize a StringRecord but ignore some columns. The columns aren't known at compile time.

It's easy to find their positions and grab the cells with StringRecord::get but this doesn't make use of the deserializer so I have to infer/guess the type myself. Which really isn't all that bad really, but it might be favourable to use the serde infrastructure.

In my scenario, the columns I'm interested in deserializing is only known at run time. I can't figure out how to get this to work in the current API this crate provides. Here's the two things I've tried.

  1. I could use DeserializeSeed to deserialize a row using a stateful object that knows what what cells to skip over and which to deserialize. However, this takes a Deserializer and this library doesn't appear to offer that in the API.

  2. Since I know what cells I need, I could also use a form of StringRecord::get that also takes a type parameter that implements Deserialize and deserializes the cell to that type. Sort of like StringRecord::deserialize but for just the cell instead of the entire row.

Is there any way to accomplish what I'm trying to do using the current API that I've missed?

@sqwishy sqwishy changed the title Question about deserializing with serde::de::DeserializeSeed Question about deserializing with serde::de::DeserializeSeed Dec 29, 2021
@BurntSushi
Copy link
Owner

I don't believe there is any way to do what you want with the current API, and I think making it possible would be a fair bit of work and an addition of a decent bit of complexity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants