PRNGSerialize

Trait PRNGSerialize 

Source
pub trait PRNGSerialize: PRNGenerator {
    type SerializeError: Into<SerializeError> + ReprC;
    type DeserializeError: Into<DeserializeError> + ReprC;

    const MAX_SERIALIZED_SIZE: usize;

    // Required methods
    fn serialize(
        &self,
        buffer: &mut [u8],
    ) -> Result<usize, Self::SerializeError>;
    fn deserialize(
        buffer: &[u8],
    ) -> Result<DeserializationResult<Self>, Self::DeserializeError>;
}
Expand description

Represents platform independent (de)serialization trait of given pseudo random number generator.

Required Associated Constants§

Source

const MAX_SERIALIZED_SIZE: usize

The maximum size of serialized value, in bytes. This should be used by callers to determine how big the buffer needs to be for PRNGSerialize::serialize to succeed.

Typically this should be in the order of few kb max (e.g. for the 128-bit linear congruential generator that would be the current state, i.e. only 16 bytes if we don’t count the multiplier and the increment). But of course there is no such guarantee in general.

Required Associated Types§

Source

type SerializeError: Into<SerializeError> + ReprC

Concrete serialization error.

Source

type DeserializeError: Into<DeserializeError> + ReprC

Concrete deserialization error.

Required Methods§

Source

fn serialize(&self, buffer: &mut [u8]) -> Result<usize, Self::SerializeError>

Serializes self into the buffer. Returns the actual amount of bytes that were written on success.

§Errors

For errors see concrete PRNGSerialize::SerializeError type.

Source

fn deserialize( buffer: &[u8], ) -> Result<DeserializationResult<Self>, Self::DeserializeError>

Deserializes self from the passed buffer. Returns deserialization info on success, i.e. the actual value and the amount of bytes read from the buffer.

§Errors

For errors see concrete PRNGSerialize::DeserializeError type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§