-
-
Notifications
You must be signed in to change notification settings - Fork 826
Can you help me figure out how to add serde to this struct? #1207
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
Labels
Comments
You may need to use a handwritten generic type bound to enforce that R::Results is serializable and deserializable. #[derive(Serialize, Deserialize)]
pub struct BlockRng<R: BlockRngCore + ?Sized> {
#[serde(bound(
serialize = "R::Results: Serialize",
deserialize = "R::Results: Deserialize<'de>"))]
pub results: R::Results,
pub index: usize,
pub core: R,
} |
Thank you! I'll try that soon, but it would have taken me hours more to find, even with the good documentation! |
It works 😄 . |
This has been fixed in Serde 1.0.38 so the original code should work as written and the bounds on the associated type can be inferred. #[derive(Serialize, Deserialize)]
struct BlockRng<R: BlockRngCore + ?Sized> {
results: R::Results,
index: usize,
core: R,
} |
Wow, that is nice! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In rust-random/rand#325 I am trying to add serde to struct, with no luck. I am kind of lost in the trait bound errors. Can you help me out?
By now I have serialization working, but no idea where to start with deserialization.
Is is about a struct where one field is a generic:
Please see the linked PR for my latest attempt.
The text was updated successfully, but these errors were encountered: