Trait BitWrite
trait BitWrite
A trait for anything that can write a variable number of potentially un-aligned values to an output stream
Required Methods
fn write_bit(self: &mut Self, bit: bool) -> Result<()>Writes a single bit to the stream.
trueindicates 1,falseindicates 0Errors
Passes along any I/O error from the underlying stream.
fn write<U>(self: &mut Self, bits: u32, value: U) -> Result<()> where U: NumericWrites 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.
fn write_signed<S>(self: &mut Self, bits: u32, value: S) -> Result<()> where S: SignedNumericWrites 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 number of bits is 0, since one bit is always needed for the sign. Returns an error if the value is too large to fit the given number of bits.
fn write_from<V>(self: &mut Self, value: V) -> Result<()> where V: PrimitiveWrites whole value to the stream whose size in bits is equal to its type's size.
Errors
Passes along any I/O error from the underlying stream.
fn write_as_from<F, V>(self: &mut Self, value: V) -> Result<()> where F: Endianness, V: PrimitiveWrites whole value to the stream whose size in bits is equal to its type's size in an endianness that may be different from the stream's endianness.
Errors
Passes along any I/O error from the underlying stream.
fn byte_aligned(self: &Self) -> boolReturns true if the stream is aligned at a whole byte.
Provided Methods
fn write_out<BITS: u32, U>(self: &mut Self, value: U) -> Result<()> where U: NumericWrites an unsigned value to the stream using the given const number of bits.
Errors
Passes along any I/O error from the underlying stream. Returns an error if the value is too large to fit the given number of bits. A compile-time error occurs if the given number of bits is larger than the output type.
fn write_signed_out<BITS: u32, S>(self: &mut Self, value: S) -> Result<()> where S: SignedNumericWrites a twos-complement signed value to the stream with the given const number of bits.
Errors
Passes along any I/O error from the underlying stream. Returns an error if the value is too large to fit the given number of bits. A compile-time error occurs if the number of bits is 0, since one bit is always needed for the sign. A compile-time error occurs if the given number of bits is larger than the output type.
fn write_bytes(self: &mut Self, buf: &[u8]) -> Result<()>Writes the entirety of a byte buffer to the stream.
Errors
Passes along any I/O error from the underlying stream.
Example
use Write; use ; let mut writer = endian; writer.write.unwrap; writer.write.unwrap; writer.write.unwrap; writer.write_bytes.unwrap; assert_eq!;fn write_unary0(self: &mut Self, value: u32) -> Result<()>Writes
valuenumber 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 Write; use ; let mut writer = endian; writer.write_unary0.unwrap; writer.write_unary0.unwrap; writer.write_unary0.unwrap; assert_eq!;use Write; use ; let mut writer = endian; writer.write_unary0.unwrap; writer.write_unary0.unwrap; writer.write_unary0.unwrap; assert_eq!;fn write_unary1(self: &mut Self, value: u32) -> Result<()>Writes
valuenumber 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 Write; use ; let mut writer = endian; writer.write_unary1.unwrap; writer.write_unary1.unwrap; writer.write_unary1.unwrap; assert_eq!;use Write; use ; let mut writer = endian; writer.write_unary1.unwrap; writer.write_unary1.unwrap; writer.write_unary1.unwrap; assert_eq!;fn build<T: ToBitStream>(self: &mut Self, build: &T) -> Result<(), <T as >::Error>Builds and writes complex type
fn build_with<'a, T: ToBitStreamWith<'a>>(self: &mut Self, build: &T, context: &<T as >::Context) -> Result<(), <T as >::Error>Builds and writes complex type with context
fn byte_align(self: &mut Self) -> Result<()>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 Write; use ; let mut writer = endian; writer.write.unwrap; writer.byte_align.unwrap; writer.write.unwrap; assert_eq!;
Implementors
impl<N, E> BitWrite for BitRecorder<N, E>impl<N, E> BitWrite for BitCounter<N, E>impl<W: io::Write, E: Endianness> BitWrite for BitWriter<W, E>