pub trait Sv2DataType<'a>:
Sized
+ SizeHint
+ GetSize
+ TryInto<FieldMarker> {
// Required methods
fn from_bytes_unchecked(data: &'a mut [u8]) -> Self;
fn from_vec_(data: Vec<u8>) -> Result<Self, Error>;
fn from_vec_unchecked(data: Vec<u8>) -> Self;
fn to_slice_unchecked(&'a self, dst: &mut [u8]);
// Provided methods
fn from_bytes_(data: &'a mut [u8]) -> Result<Self, Error> { ... }
fn to_slice(&'a self, dst: &mut [u8]) -> Result<usize, Error> { ... }
}Expand description
Sv2DataType is a trait that defines methods for encoding and decoding Stratum V2 data.
It is used for serializing and deserializing both fixed-size and dynamically-sized types.
Key Responsibilities:
- Serialization: Converting data from in-memory representations to byte slices or streams.
- Deserialization: Converting byte slices or streams back into the in-memory representation of the data.
This trait includes functions for both checked and unchecked conversions, providing flexibility in situations where error handling can be safely ignored.
Required Methods§
Sourcefn from_bytes_unchecked(data: &'a mut [u8]) -> Self
fn from_bytes_unchecked(data: &'a mut [u8]) -> Self
Constructs an instance from a mutable byte slice without verifying size constraints.
Sourcefn from_vec_(data: Vec<u8>) -> Result<Self, Error>
fn from_vec_(data: Vec<u8>) -> Result<Self, Error>
Constructs an instance from a vector, checking for the correct size.
Sourcefn from_vec_unchecked(data: Vec<u8>) -> Self
fn from_vec_unchecked(data: Vec<u8>) -> Self
Constructs an instance from a vector without validating its size.
Sourcefn to_slice_unchecked(&'a self, dst: &mut [u8])
fn to_slice_unchecked(&'a self, dst: &mut [u8])
Serializes the instance to a mutable slice without checking the destination size.
Provided Methods§
Sourcefn from_bytes_(data: &'a mut [u8]) -> Result<Self, Error>
fn from_bytes_(data: &'a mut [u8]) -> Result<Self, Error>
Creates an instance of the type from a mutable byte slice, checking for size constraints.
This function verifies that the provided byte slice has the correct size according to the type’s size hint.
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.