[−][src]Trait peek_poke::Peek
A trait for values that provide deserialization from buffers of bytes.
Example
ⓘThis example is not tested
use peek_poke::Peek; struct Bar { a: u32, b: u8, c: i16, } ... impl Peek for Bar { unsafe fn peek_from(&mut self, bytes: *const u8) -> *const u8 { let bytes = self.a.peek_from(bytes); let bytes = self.b.peek_from(bytes); self.c.peek_from(bytes) } }
Safety
The Peek trait contains unsafe methods for the following reasons, and
implementors must ensure that they adhere to these contracts:
- Callers of this trait are expected to rely on the contract defined on each
method, and implementors must ensure that
peek_from()doesn't read more bytes frombytesthan is returned byPeek::max_size().
Required methods
unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8
Deserialize from the buffer pointed to by bytes.
Returns a pointer to the next byte after the unconsumed bytes not used
to deserialize the representation of Self.
Safety
This function is unsafe because undefined behavior can result if the caller does not ensure all of the following:
-
bytesmust denote a valid pointer to a block of memory. -
bytesmust pointer to at least the number of bytes returned byPoke::max_size().