[][src]Trait peek_poke::Poke

pub unsafe trait Poke {
    fn max_size() -> usize;
unsafe fn poke_into(&self, bytes: *mut u8) -> *mut u8; }

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

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.

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().

Loading content...

Implementations on Foreign Types

impl<'a, T: Poke> Poke for &'a T[src]

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

impl Poke for i8[src]

impl Poke for i16[src]

impl Poke for i32[src]

impl Poke for i64[src]

impl Poke for isize[src]

impl Poke for u8[src]

impl Poke for u16[src]

impl Poke for u32[src]

impl Poke for u64[src]

impl Poke for usize[src]

impl Poke for f32[src]

impl Poke for f64[src]

impl Poke for bool[src]

impl<T> Poke for PhantomData<T>[src]

impl<T: Poke> Poke for Option<T>[src]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl Poke for ()[src]

impl<A: Poke> Poke for (A,)[src]

impl<A: Poke, B: Poke> Poke for (A, B)[src]

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

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

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

Loading content...

Implementors

Loading content...