Trait bitstream_io::write::ByteWrite
source · pub trait ByteWrite {
// Required methods
fn write<N: Numeric>(&mut self, value: N) -> Result<()>;
fn write_bytes(&mut self, buf: &[u8]) -> Result<()>;
fn writer_ref(&mut self) -> &mut dyn Write;
// Provided methods
fn build<T: ToByteStream>(&mut self, build: &T) -> Result<(), T::Error> { ... }
fn build_with<T: ToByteStreamWith>(
&mut self,
build: &T,
context: &T::Context
) -> Result<(), T::Error> { ... }
}
Expand description
A trait for anything that can write aligned values to an output stream
Required Methods§
sourcefn write<N: Numeric>(&mut self, value: N) -> Result<()>
fn write<N: Numeric>(&mut self, value: N) -> Result<()>
Writes whole numeric value to stream
§Errors
Passes along any I/O error from the underlying stream.
§Examples
use std::io::Write;
use bitstream_io::{BigEndian, ByteWriter, ByteWrite};
let mut writer = ByteWriter::endian(Vec::new(), BigEndian);
writer.write(0b0000000011111111u16).unwrap();
assert_eq!(writer.into_writer(), [0b00000000, 0b11111111]);
use std::io::Write;
use bitstream_io::{LittleEndian, ByteWriter, ByteWrite};
let mut writer = ByteWriter::endian(Vec::new(), LittleEndian);
writer.write(0b0000000011111111u16).unwrap();
assert_eq!(writer.into_writer(), [0b11111111, 0b00000000]);
sourcefn write_bytes(&mut self, buf: &[u8]) -> Result<()>
fn write_bytes(&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.
sourcefn writer_ref(&mut self) -> &mut dyn Write
fn writer_ref(&mut self) -> &mut dyn Write
Returns mutable reference to underlying writer
Provided Methods§
sourcefn build<T: ToByteStream>(&mut self, build: &T) -> Result<(), T::Error>
fn build<T: ToByteStream>(&mut self, build: &T) -> Result<(), T::Error>
Builds and writes complex type
sourcefn build_with<T: ToByteStreamWith>(
&mut self,
build: &T,
context: &T::Context
) -> Result<(), T::Error>
fn build_with<T: ToByteStreamWith>( &mut self, build: &T, context: &T::Context ) -> Result<(), T::Error>
Builds and writes complex type with context
Object Safety§
This trait is not object safe.