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

Recursive Types #29

Open
NiklasVousten opened this issue Oct 21, 2023 · 0 comments
Open

Recursive Types #29

NiklasVousten opened this issue Oct 21, 2023 · 0 comments

Comments

@NiklasVousten
Copy link

While code for a schema with recursion is currently generated, it can not compile.
It can be fixed manually by saving the code with the store_generated_code option and then adding a Box around the compilation issue.

Furthermore a custom YaSerialize and YaDeserialize has to be implemented for every boxed type, because yaserde is not supporting Box currently.

Adding the boxed serialization can be done like this:

impl yaserde::YaDeserialize for Box<BoxedType> {
    fn deserialize<R: Read>(reader: &mut yaserde::de::Deserializer<R>) -> Result<Self, String> {
        BoxedType::deserialize(reader).map(Box::new)
    }
}

impl yaserde::YaSerialize for Box<BoxedType> {
    fn serialize<W: Write>(&self, writer: &mut yaserde::ser::Serializer<W>) -> Result<(), String> {
        BoxedType::serialize(&self, writer)
    }
}

Because I had no usecase for the attribute, I have no code example for the serialization of these.

An automatic wrapping of these types into Box would allow easier use of this crate.

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

1 participant