Skip to main content

Sink

Trait Sink 

Source
pub trait Sink {
    // Required methods
    fn write_bits(&mut self, value: u128, n: u32) -> Result<(), BitError>;
    fn bit_pos(&self) -> usize;

    // Provided methods
    fn byte_order(&self) -> ByteOrder { ... }
    fn write<T: Bits>(&mut self, value: T) -> Result<(), BitError> { ... }
    fn as_write(&mut self) -> SinkWriter<'_, Self> 
       where Self: Sized { ... }
}
Expand description

A bit-level output the codec writes to — the in-memory BitWriter (and, under the bytes feature, BytesWriter). Encode to any std::io::Write via a message’s generated encode method.

§Examples

use bnb::{BitWriter, Sink, u4};

// A writer generic over any `Sink`.
fn put_nibble<K: Sink>(k: &mut K, v: u4) { k.write(v).unwrap(); }

let mut w = BitWriter::new();
put_nibble(&mut w, u4::new(0xA));
put_nibble(&mut w, u4::new(0x5));
assert_eq!(w.into_bytes(), [0xA5]);

Required Methods§

Source

fn write_bits(&mut self, value: u128, n: u32) -> Result<(), BitError>

Appends the low n (<= 128) bits of value, MSB-first.

§Errors

Propagates the writer’s BitError.

Source

fn bit_pos(&self) -> usize

The number of bits written so far.

Provided Methods§

Source

fn byte_order(&self) -> ByteOrder

The byte order applied to a byte-multiple value (default big-endian).

Source

fn write<T: Bits>(&mut self, value: T) -> Result<(), BitError>

Appends one Bits value of its declared width, applying the byte order.

§Errors

As write_bits.

Source

fn as_write(&mut self) -> SinkWriter<'_, Self>
where Self: Sized,

Borrows this sink as a std::io::Write — the dual of Source::as_read, for handing the cursor to std::io-based code from a #[bw(write_with = …)]. Writes 8 bits per byte; see SinkWriter. Only with the std feature.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§