peek_poke

Trait Poke

Source
pub unsafe trait Poke {
    // Required methods
    fn max_size() -> usize;
    unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8;
}
Expand description

A trait for values that provide serialization into buffers of bytes.

§Example

use peek_poke::Poke;

struct Bar {
    a: u32,
    b: u8,
    c: i16,
}

unsafe impl Poke for Bar {
    fn max_size() -> usize {
        <u32>::max_size() + <u8>::max_size() + <i16>::max_size()
    }
    unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8 {
        let bytes = self.a.poke_into(bytes);
        let bytes = self.b.poke_into(bytes);
        self.c.poke_into(bytes)
    }
}

§Safety

The Poke trait is an unsafe trait for the reasons, and implementors must ensure that they adhere to these contracts:

  • max_size() query and calculations in general must be correct. Callers of this trait are expected to rely on the contract defined on each method, and implementors must ensure such contracts remain true.

Required Methods§

Source

fn max_size() -> usize

Return the maximum number of bytes that the serialized version of Self will occupy.

§Safety

Implementors of Poke guarantee to not write more than the result of calling max_size() into the buffer pointed to by bytes when poke_into() is called.

Source

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Serialize into the buffer pointed to by bytes.

Returns a pointer to the next byte after the serialized representation of Self.

§Safety

This function is unsafe because undefined behavior can result if the caller does not ensure all of the following:

  • bytes must denote a valid pointer to a block of memory.

  • bytes must pointer to at least the number of bytes returned by max_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 Poke for bool

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for f32

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for f64

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for i8

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for i16

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for i32

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for i64

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for isize

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for u8

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for u16

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for u32

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for u64

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for ()

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl Poke for usize

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<'a, T: Poke> Poke for &'a T

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<'a, T: Poke> Poke for &'a mut T

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<A: Poke> Poke for (A,)

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<A: Poke, B: Poke> Poke for (A, B)

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<A: Poke, B: Poke, C: Poke> Poke for (A, B, C)

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<A: Poke, B: Poke, C: Poke, D: Poke> Poke for (A, B, C, D)

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<A: Poke, B: Poke, C: Poke, D: Poke, E: Poke> Poke for (A, B, C, D, E)

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T> Poke for PhantomData<T>

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for Option<T>

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 1]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 2]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 3]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 4]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 5]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 6]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 7]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 8]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 9]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 10]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 11]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 12]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 13]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 14]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 15]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 16]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 17]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 18]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 19]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 20]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 21]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 22]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 23]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 24]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 25]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 26]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 27]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 28]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 29]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 30]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 31]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Source§

impl<T: Poke> Poke for [T; 32]

Source§

fn max_size() -> usize

Source§

unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8

Implementors§