[][src]Trait byte::TryWrite

pub trait TryWrite<Ctx = ()> {
    fn try_write(self, bytes: &mut [u8], ctx: Ctx) -> Result<usize>;
}

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)
    }
}
Loading content...

Implementors

impl TryWrite<()> for bool[src]

impl TryWrite<Endian> for i8[src]

impl TryWrite<Endian> for i16[src]

impl TryWrite<Endian> for i32[src]

impl TryWrite<Endian> for i64[src]

impl TryWrite<Endian> for isize[src]

impl TryWrite<Endian> for u8[src]

impl TryWrite<Endian> for u16[src]

impl TryWrite<Endian> for u32[src]

impl TryWrite<Endian> for u64[src]

impl TryWrite<Endian> for usize[src]

impl<'a> TryWrite<()> for &'a [u8][src]

impl<'a> TryWrite<()> for &'a str[src]

impl<'a> TryWrite<Endian> for f32[src]

impl<'a> TryWrite<Endian> for f64[src]

Loading content...