Sv2DataType

Trait Sv2DataType 

Source
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§

Source

fn from_bytes_unchecked(data: &'a mut [u8]) -> Self

Constructs an instance from a mutable byte slice without verifying size constraints.

Source

fn from_vec_(data: Vec<u8>) -> Result<Self, Error>

Constructs an instance from a vector, checking for the correct size.

Source

fn from_vec_unchecked(data: Vec<u8>) -> Self

Constructs an instance from a vector without validating its size.

Source

fn to_slice_unchecked(&'a self, dst: &mut [u8])

Serializes the instance to a mutable slice without checking the destination size.

Provided Methods§

Source

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.

Source

fn to_slice(&'a self, dst: &mut [u8]) -> Result<usize, Error>

Serializes the instance to a mutable slice, checking the destination size.

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.

Implementations on Foreign Types§

Source§

impl<'a> Sv2DataType<'a> for bool

Source§

fn from_bytes_unchecked(data: &'a mut [u8]) -> Self

Source§

fn from_vec_(data: Vec<u8>) -> Result<Self, Error>

Source§

fn from_vec_unchecked(data: Vec<u8>) -> Self

Source§

fn to_slice_unchecked(&'a self, dst: &mut [u8])

Source§

impl<'a> Sv2DataType<'a> for f32

Source§

fn from_bytes_unchecked(data: &'a mut [u8]) -> Self

Source§

fn from_vec_(data: Vec<u8>) -> Result<Self, Error>

Source§

fn from_vec_unchecked(data: Vec<u8>) -> Self

Source§

fn to_slice_unchecked(&'a self, dst: &mut [u8])

Source§

impl<'a> Sv2DataType<'a> for u8

Source§

fn from_bytes_unchecked(data: &'a mut [u8]) -> Self

Source§

fn from_vec_(data: Vec<u8>) -> Result<Self, Error>

Source§

fn from_vec_unchecked(data: Vec<u8>) -> Self

Source§

fn to_slice_unchecked(&'a self, dst: &mut [u8])

Source§

impl<'a> Sv2DataType<'a> for u16

Source§

fn from_bytes_unchecked(data: &'a mut [u8]) -> Self

Source§

fn from_vec_(data: Vec<u8>) -> Result<Self, Error>

Source§

fn from_vec_unchecked(data: Vec<u8>) -> Self

Source§

fn to_slice_unchecked(&'a self, dst: &mut [u8])

Source§

impl<'a> Sv2DataType<'a> for u32

Source§

fn from_bytes_unchecked(data: &'a mut [u8]) -> Self

Source§

fn from_vec_(data: Vec<u8>) -> Result<Self, Error>

Source§

fn from_vec_unchecked(data: Vec<u8>) -> Self

Source§

fn to_slice_unchecked(&'a self, dst: &mut [u8])

Source§

impl<'a> Sv2DataType<'a> for u64

Source§

fn from_bytes_unchecked(data: &'a mut [u8]) -> Self

Source§

fn from_vec_(data: Vec<u8>) -> Result<Self, Error>

Source§

fn from_vec_unchecked(data: Vec<u8>) -> Self

Source§

fn to_slice_unchecked(&'a self, dst: &mut [u8])

Implementors§

Source§

impl<'a> Sv2DataType<'a> for U24