pub trait BitWrite: Send {
// Required methods
fn write_bit<'life0, 'async_trait>(
&'life0 mut self,
bit: bool,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn write<'life0, 'async_trait, U>(
&'life0 mut self,
bits: u32,
value: U,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where U: Numeric + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn write_signed<'life0, 'async_trait, S>(
&'life0 mut self,
bits: u32,
value: S,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where S: SignedNumeric + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn byte_aligned(&self) -> bool;
// Provided methods
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 { ... }
fn write_unary0<'life0, 'async_trait>(
&'life0 mut self,
value: u32,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn write_unary1<'life0, 'async_trait>(
&'life0 mut self,
value: u32,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn byte_align<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}
Expand description
A trait for anything that can write a variable number of potentially un-aligned values to an output stream
Required Methods§
Sourcefn write_bit<'life0, 'async_trait>(
&'life0 mut self,
bit: bool,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn write_bit<'life0, 'async_trait>(
&'life0 mut self,
bit: bool,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Writes a single bit to the stream.
true
indicates 1, false
indicates 0
§Errors
Passes along any I/O error from the underlying stream.
Sourcefn write<'life0, 'async_trait, U>(
&'life0 mut self,
bits: u32,
value: U,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
U: Numeric + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
fn write<'life0, 'async_trait, U>(
&'life0 mut self,
bits: u32,
value: U,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
U: Numeric + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
Writes an unsigned value to the stream using the given number of bits.
§Errors
Passes along any I/O error from the underlying stream. Returns an error if the input type is too small to hold the given number of bits. Returns an error if the value is too large to fit the given number of bits.
Sourcefn write_signed<'life0, 'async_trait, S>(
&'life0 mut self,
bits: u32,
value: S,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
S: SignedNumeric + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
fn write_signed<'life0, 'async_trait, S>(
&'life0 mut self,
bits: u32,
value: S,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
S: SignedNumeric + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
Writes a twos-complement signed value to the stream with the given number of bits.
§Errors
Passes along any I/O error from the underlying stream. Returns an error if the input type is too small to hold the given number of bits. Returns an error if the value is too large to fit the given number of bits.
Sourcefn byte_aligned(&self) -> bool
fn byte_aligned(&self) -> bool
Returns true if the stream is aligned at a whole byte.
Provided Methods§
Sourcefn 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,
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.
§Example
use std::io::Write;
use tokio_bitstream_io::{BigEndian, BitWriter, BitWrite};
let mut writer = BitWriter::endian(Vec::new(), BigEndian);
writer.write(8, 0x66).await.unwrap();
writer.write(8, 0x6F).await.unwrap();
writer.write(8, 0x6F).await.unwrap();
writer.write_bytes(b"bar").await.unwrap();
assert_eq!(writer.into_writer(), b"foobar");
Sourcefn write_unary0<'life0, 'async_trait>(
&'life0 mut self,
value: u32,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn write_unary0<'life0, 'async_trait>(
&'life0 mut self,
value: u32,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Writes value
number of 1 bits to the stream
and then writes a 0 bit. This field is variably-sized.
§Errors
Passes along any I/O error from the underyling stream.
§Examples
use tokio_bitstream_io::{BigEndian, BitWriter, BitWrite};
let mut writer = BitWriter::endian(Vec::new(), BigEndian);
writer.write_unary0(0).await.unwrap();
writer.write_unary0(3).await.unwrap();
writer.write_unary0(10).await.unwrap();
assert_eq!(writer.into_writer(), [0b01110111, 0b11111110]);
use tokio_bitstream_io::{LittleEndian, BitWriter, BitWrite};
let mut writer = BitWriter::endian(Vec::new(), LittleEndian);
writer.write_unary0(0).await.unwrap();
writer.write_unary0(3).await.unwrap();
writer.write_unary0(10).await.unwrap();
assert_eq!(writer.into_writer(), [0b11101110, 0b01111111]);
Sourcefn write_unary1<'life0, 'async_trait>(
&'life0 mut self,
value: u32,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn write_unary1<'life0, 'async_trait>(
&'life0 mut self,
value: u32,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Writes value
number of 0 bits to the stream
and then writes a 1 bit. This field is variably-sized.
§Errors
Passes along any I/O error from the underyling stream.
§Example
use tokio_bitstream_io::{BigEndian, BitWriter, BitWrite};
let mut writer = BitWriter::endian(Vec::new(), BigEndian);
writer.write_unary1(0).await.unwrap();
writer.write_unary1(3).await.unwrap();
writer.write_unary1(10).await.unwrap();
assert_eq!(writer.into_writer(), [0b10001000, 0b00000001]);
use tokio_bitstream_io::{LittleEndian, BitWriter, BitWrite};
let mut writer = BitWriter::endian(Vec::new(), LittleEndian);
writer.write_unary1(0).await.unwrap();
writer.write_unary1(3).await.unwrap();
writer.write_unary1(10).await.unwrap();
assert_eq!(writer.into_writer(), [0b00010001, 0b10000000]);
Sourcefn byte_align<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn byte_align<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Pads the stream with 0 bits until it is aligned at a whole byte. Does nothing if the stream is already aligned.
§Errors
Passes along any I/O error from the underyling stream.
§Example
use std::io::Write;
use tokio_bitstream_io::{BigEndian, BitWriter, BitWrite};
let mut writer = BitWriter::endian(Vec::new(), BigEndian);
writer.write(1, 0).await.unwrap();
writer.byte_align().await.unwrap();
writer.write(8, 0xFF).await.unwrap();
assert_eq!(writer.into_writer(), [0x00, 0xFF]);
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.