Skip to content

Complex Serialisation #17

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

Closed
wants to merge 4 commits into from
Closed

Complex Serialisation #17

wants to merge 4 commits into from

Conversation

28Smiles
Copy link

@28Smiles 28Smiles commented Dec 24, 2022

This is a first draft on complex type serialisation #6. The code is in heavy development and a complete mess.
To be as maintainable as possible the macro creates internal structs and uses the serde::Serialize macro for serialisation, where possible.

Implementation State

Serialisation:

  • Unit Modus (serialize as an integer type)
  • Externally Tagged ({"42": { ... }})
  • Internally Tagged ({"tag": 42, ... })
  • Adjacently Tagged ({"tag": 42, "content": {...}})

Deserialisation:

  • Unit Modus (deserialize as an integer type)
  • Externally Tagged ({"42": { ... }})
  • Internally Tagged ({"tag": 42, ... })
  • Adjacently Tagged ({"tag": 42, "content": {...}})

Changes in Behavior of the Previous Macro

I have not found any

Internal Changes of generated Code

  • Uses the expression of the variant instead of casting, since this is not possible with non unit variants
  • The Unit case is reimplemented, with some minor changes.

@28Smiles 28Smiles marked this pull request as draft December 24, 2022 04:45
@28Smiles 28Smiles changed the title Draft: Complex Serialisation Complex Serialisation Dec 24, 2022
@28Smiles
Copy link
Author

Serialisation is now fully functional, I will continue working on deserialisation, but this will be harder since i need to work with visitors.

@28Smiles
Copy link
Author

28Smiles commented Dec 26, 2022

I also introduced the const_format crate, since it is the only way for me to create a compiletime static string from an const expression.

@28Smiles
Copy link
Author

@dtolnay I hope its okay if I ping you here, I would really appreciate some input from your side.

@@ -79,3 +79,32 @@ mod implicit_discriminant {
assert_eq!(p, ImplicitDiscriminant::Two);
}
}

mod externally_tagged_complex_enum {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here an example of the current capabillities

@28Smiles
Copy link
Author

Also, i know the code is a complete mess rn, but there are a lot of cases to cover, while beeing heavily codependent, but I will look into modularizing this suff once all represenations are covered.

@28Smiles
Copy link
Author

28Smiles commented Jan 1, 2023

I decided to implement this in the main serde derive macro, since there are a lot of edge cases. With this full support should be garanteed. serde-rs/serde#2354

@28Smiles 28Smiles closed this Jan 1, 2023
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.

1 participant