Trait ByteWrite

Source
pub trait ByteWrite {
    // Required methods
    fn write<'life0, 'async_trait, N>(
        &'life0 mut self,
        value: N,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where N: 'async_trait + Numeric,
             Self: 'async_trait,
             'life0: 'async_trait;
    fn write_bytes<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        buf: &'life1 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

A trait for anything that can write aligned values to an output stream

Required Methods§

Source

fn write<'life0, 'async_trait, N>( &'life0 mut self, value: N, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where N: 'async_trait + Numeric, Self: 'async_trait, 'life0: 'async_trait,

Writes whole numeric value to stream

§Errors

Passes along any I/O error from the underlying stream.

§Examples
use tokio_bitstream_io::{BigEndian, ByteWriter, ByteWrite};
let mut writer = ByteWriter::endian(Vec::new(), BigEndian);
writer.write(0b0000000011111111u16).await.unwrap();
assert_eq!(writer.into_writer(), [0b00000000, 0b11111111]);
use tokio_bitstream_io::{LittleEndian, ByteWriter, ByteWrite};
let mut writer = ByteWriter::endian(Vec::new(), LittleEndian);
writer.write(0b0000000011111111u16).await.unwrap();
assert_eq!(writer.into_writer(), [0b11111111, 0b00000000]);
Source

fn write_bytes<'life0, 'life1, 'async_trait>( &'life0 mut self, buf: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Writes the entirety of a byte buffer to the stream.

§Errors

Passes along any I/O error from the underlying stream.

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.

Implementors§