feat(serde)!: use internal serialization to roundtrip crate types #135
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BREAKING CHANGE:
hcl::ser::Serializer
does not implementserde::Serializer
anymore. Useserializer.serialize(&value)
in places wherevalue.serialize(&mut serializer)
was used before.This essentially uses the approach that the author of
minijinja
describes in this blog post: https://lucumr.pocoo.org/2021/11/14/abusing-serde/I originally read this before I even added serialization support to
hcl-rs
and decided back then to go without internal serialization.However, the number of types involved to represent the HCL structural, expression and template languages now makes it necessary to switch to internal serialization since each type needs a custom serializer implementation just for the sake of roundtripping it through
serde
. The amount of code that I wrote to make this work is already quite massive and would even get bigger once serialization of template viaserde
is fully supported. Also it was quite messy.Thus, I switched to internal serialization to roundtrip all expression and structure types. This meant that I could remove a lot of custom serializers.
This also had some positive side effects:
#[serde(rename = "$hcl::...")]
markers could be removed almost everywhere since they were only needed to make the roundtripping through serde work. The only type that still has this marker isBody
since we need to special-case it during deserialization.custom_blocks
test insrc/structure/ser/tests.rs
should give a first hint how this will work.