Struct BitWriter

Source
pub struct BitWriter<W, P>
where W: Write, P: Padding,
{ /* private fields */ }
Expand description

BitWriter is a writer for single bit values

Bits will be grouped to a single byte before writing to the inner writer. The first Bit will be the most significant bit of the byte.

When dropping this writer, any remaining bits will be written according to the padding used. The default padding is NoPadding

§Examples

extern crate bitstream;

let vec = Vec::new();
let mut bit_writer = bitstream::BitWriter::new(vec);

assert!(bit_writer.write_bit(true).is_ok());
assert!(bit_writer.write_bit(false).is_ok());

Implementations§

Source§

impl<W> BitWriter<W, NoPadding>
where W: Write,

Source

pub fn new(write: W) -> Self

Create a new BitWriter with no padding, writing to the inner writer.

Source§

impl<W, P> BitWriter<W, P>
where W: Write, P: Padding,

Source

pub fn with_padding(write: W, padder: P) -> Self

Create a new BitWriter with the given padding

Source

pub fn write_bit(&mut self, bit: bool) -> IOResult<()>

Write a single bit to the inner writer.

§Failures

Returns an error if the inner writer returns an error

Trait Implementations§

Source§

impl<W, P> Drop for BitWriter<W, P>
where W: Write, P: Padding,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<W, P> Freeze for BitWriter<W, P>
where W: Freeze, P: Freeze,

§

impl<W, P> RefUnwindSafe for BitWriter<W, P>

§

impl<W, P> Send for BitWriter<W, P>
where W: Send, P: Send,

§

impl<W, P> Sync for BitWriter<W, P>
where W: Sync, P: Sync,

§

impl<W, P> Unpin for BitWriter<W, P>
where W: Unpin, P: Unpin,

§

impl<W, P> UnwindSafe for BitWriter<W, P>
where W: UnwindSafe, P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.