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

Impl YaDeserialize for a type that should be treated as Primitive #148

Open
rrichardson opened this issue Oct 5, 2022 · 2 comments
Open

Comments

@rrichardson
Copy link

rrichardson commented Oct 5, 2022

I am baffled. I can run the examples crate tests just fine.

However, when I run this on my own code, deriving YaDeserialize fails because the constraint of T: YaDeserialize isn't met because T doesn't implement YaDeserialize.

This is for types like i32, String, etc.

I have looked through the code and I don't see anywhere where YaDeserialize is implemented for anything, so I have no idea how the examples crate works, where it has some fields which are String.

*Edit*

I ran cargo-expand, and now understand how it avoids needing to impl YaDeserialize for primitive types. It bakes the from_str directly into the struct's deserialization routine (that seems like it'd cause a lot of unnecessary code duplication, but I guess that pertains to the RFC for the API redesign)

I guess my more fundamental question is:

How can I impl YaDeserialize for a custom type which I basically want to treat as a String it's a specially formatted Timestamp which will always serialize to a String-ish type, and always be parsed from a String-ish type. So it shouldn't have any properties, etc.

At the moment, I'm attempting to duplicate the impl for i32 and string members that I find.

However, I'm not sure how I can direct yaserde_derive::YaDeserialize to fetch the type correctly, since I basically want to treat it as a primitive.

@rrichardson rrichardson changed the title Where are the YaDeserialize impls for primitive types? Impl YaDeserialize for a type that should be treated as Primitive Oct 6, 2022
@mlevkov
Copy link

mlevkov commented Oct 31, 2022

@rrichardson I've put together an example of how you can do this for your own types
here is the example -> #87

@nrbnlulu
Copy link

You can use

use xsd_macro_utils::UtilsDefaultSerde;

#[derive(Default, PartialEq, Debug, UtilsTupleIo, UtilsDefaultSerde)]
pub struct YourCustomType(pub String);

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

3 participants