pub trait Peek: Poke {
// Required method
unsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8;
}
Expand description
A trait for values that provide deserialization from buffers of bytes.
§Example
ⓘ
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 frombytes
than is returned byPeek::max_size()
.
Required Methods§
Sourceunsafe fn peek_from(bytes: *const u8, output: *mut Self) -> *const u8
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:
-
bytes
must denote a valid pointer to a block of memory. -
bytes
must pointer to at least the number of bytes returned byPoke::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.