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§
Sourceconst MAX_SERIALIZED_SIZE: usize
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§
Sourcetype SerializeError: Into<SerializeError> + ReprC
type SerializeError: Into<SerializeError> + ReprC
Concrete serialization error.
Sourcetype DeserializeError: Into<DeserializeError> + ReprC
type DeserializeError: Into<DeserializeError> + ReprC
Concrete deserialization error.
Required Methods§
Sourcefn serialize(&self, buffer: &mut [u8]) -> Result<usize, Self::SerializeError>
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.
Sourcefn deserialize(
buffer: &[u8],
) -> Result<DeserializationResult<Self>, Self::DeserializeError>
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.