Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(serde)!: use internal serialization to roundtrip crate types (#135)
BREAKING CHANGE: `hcl::ser::Serializer` does not implement `serde::Serializer` anymore. Use `serializer.serialize(&value)` in places where `value.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 via `serde` 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: - The `#[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 is `Body` since we need to special-case it during deserialization. - The serializer code is much cleaner now. - Serialization of types that are subject to roundtripping is quite a bit faster. - It is now possible (and this change already implements most of it) to properly support serialization of HCL blocks (with or without labels) from custom types. The public API and documentation for this will be added as a followup. The `custom_blocks` test in `src/structure/ser/tests.rs` should give a first hint how this will work.
- Loading branch information
1 parent
e39927d
commit fbd555b
Showing
33 changed files
with
1,798 additions
and
3,038 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.