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

WIP Serde #172

Merged
merged 11 commits into from
Dec 1, 2019
Merged

WIP Serde #172

merged 11 commits into from
Dec 1, 2019

Conversation

tafia
Copy link
Owner

@tafia tafia commented Nov 25, 2019

Add a serialize feature to allow (de)serializing xmls.

This is hugely inspired by serde-xml so most of the credit goes to them.

For the moment only Deserialization has been worked on. Serialization should be simpler.

In terms of performance, there is probably some optimization to do in the future. In particular we should be able to avoid the 'static lifetime in Deserializer::next (thus avoiding some unecessary allocations/copy).

@tafia
Copy link
Owner Author

tafia commented Nov 26, 2019

close #165

@elibenporat
Copy link

elibenporat commented Nov 26, 2019

Latest update worked for me, swapped out all the xml-rs for quick-xml and everything working properly.

@tafia tafia closed this Nov 26, 2019
@tafia tafia reopened this Nov 26, 2019
@elibenporat
Copy link

Not sure your opinion on this, but for http://gd2.mlb.com/components/game/mlb/year_2008/month_02/day_26/gid_2008_02_26_fanbbc_phimlb_1/players.xml I'm using this struct:

struct Team {
    #[serde(rename="type")]
    home_away: HomeAway,
    id: String,
    name: String,
    #[serde(rename="player")]
    players: Vec<Player>,
    #[serde(rename="coach")]
    coaches: Vec<Coach>,
}

This returns an Error (missing field 'coach'), since one of the teams doesn't have any coaches in the file.

Would it be better (or even possible?) to return an empty vec, rather than having to wrap the field in an option.

@tafia
Copy link
Owner Author

tafia commented Nov 29, 2019

Have you tried adding a default on this field?

    #[serde(rename="coach", default)]
    coaches: Vec<Coach>,

@elibenporat
Copy link

elibenporat commented Nov 30, 2019

Always something to learn with SerDe! Yes, that is definitely the better way to do it. QuickXML with SerDe has been working flawlessly on a pretty large sample size.

@tafia
Copy link
Owner Author

tafia commented Dec 1, 2019

Thank you for the feedbacks, it helps a lot!

- disable default `serialize` feature (must opt-in now)
- add documentation for `crate::de` module
@tafia tafia merged commit 1adfba0 into master Dec 1, 2019
@tafia tafia deleted the serde branch December 1, 2019 01:38
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

Successfully merging this pull request may close these issues.

None yet

2 participants