Trait peek_poke::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().

Object Safety§

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

source§

impl<T: Poke, S, D> Poke for Transform3D<T, S, D>

source§

fn max_size() -> usize

source§

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

source§

impl<T: Poke, U> Poke for Box2D<T, U>

source§

fn max_size() -> usize

source§

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

source§

impl<T: Poke, U> Poke for Point2D<T, U>

source§

fn max_size() -> usize

source§

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

source§

impl<T: Poke, U> Poke for Rect<T, U>

source§

fn max_size() -> usize

source§

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

source§

impl<T: Poke, U> Poke for SideOffsets2D<T, U>

source§

fn max_size() -> usize

source§

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

source§

impl<T: Poke, U> Poke for Size2D<T, U>

source§

fn max_size() -> usize

source§

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

source§

impl<T: Poke, U> Poke for Vector2D<T, U>

source§

fn max_size() -> usize

source§

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

Implementors§