[−][src]Trait byte::TryWrite
A data structure that can be serialized. Types implement this trait can be write()
into byte slice.
Required methods
fn try_write(self, bytes: &mut [u8], ctx: Ctx) -> Result<usize>
Try to write to bytes using context.
Write the value into bytes; the bytes passed in is splitted by offset and should be write at head.
If success, try_write()
should return the number of bytes written.
Example
use byte::*; pub struct HasBool(bool); impl TryWrite for HasBool { #[inline] fn try_write(self, bytes: &mut [u8], _ctx: ()) -> Result<usize> { check_len(bytes, 1)?; bytes[0] = if self.0 { u8::max_value() } else { 0 }; Ok(1) } }