Skip to content

Can you help me figure out how to add serde to this struct? #1207

@pitdicker

Description

@pitdicker

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:

pub struct BlockRng<R: BlockRngCore + ?Sized> {
    pub results: R::Results,
    pub index: usize,
    pub core: R,
}

pub trait BlockRngCore {
    type Item;

    /// Results type. This is the 'block' an RNG implementing `BlockRngCore`
    /// generates, which will usually be an array like `[u32; 16]`.
    type Results: AsRef<[Self::Item]> + AsMut<[Self::Item]> + Default;

    /// Generate a new block of results.
    fn generate(&mut self, results: &mut Self::Results);
}

Please see the linked PR for my latest attempt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions