pub struct BufferedBinaryWriter<W, O = BigEndian>{ /* private fields */ }Expand description
Buffered writer for fixed-width binary values.
Scalar writes encode directly into the internal output buffer and flush that buffer to the wrapped writer only when it becomes full or when explicitly flushed.
§Flush contract
Dropping this writer delegates to qubit_io::BufferedOutput, which makes a
best-effort attempt to drain pending bytes, ignores drop-time errors, and
does not guarantee that the wrapped writer itself is flushed. Call
Output::flush to guarantee that all bytes reach the wrapped output.
Self::inner can observe the wrapped writer before pending bytes have
been flushed.
§Type Parameters
W: Underlying byte output.O: Compile-time byte-order specification.
Implementations§
Source§impl<W, O> BufferedBinaryWriter<W, O>
impl<W, O> BufferedBinaryWriter<W, O>
Sourcepub fn with_capacity(inner: W, capacity: usize) -> Self
pub fn with_capacity(inner: W, capacity: usize) -> Self
Sourcepub fn try_with_capacity(
inner: W,
capacity: usize,
) -> Result<Self, TryReserveError>
pub fn try_with_capacity( inner: W, capacity: usize, ) -> Result<Self, TryReserveError>
Tries to create a buffered binary writer with at least capacity bytes.
§Errors
Returns an allocation error when the requested buffer cannot be allocated.
Sourcepub const fn byte_order(&self) -> ByteOrder
pub const fn byte_order(&self) -> ByteOrder
Returns the byte order selected by this writer.
§Returns
Returns the compile-time byte order as a runtime value.
Sourcepub const fn inner(&self) -> &W
pub const fn inner(&self) -> &W
Returns a shared reference to the underlying writer.
Pending bytes may still be held in this wrapper’s internal buffer.
§Returns
Returns the wrapped writer.
Sourcepub fn into_parts(self) -> (W, Buffer<u8>)
pub fn into_parts(self) -> (W, Buffer<u8>)
This method does not call Self::flush and performs no I/O. Pending
bytes in the returned buffer have already been accepted by this writer
but have not reached the returned writer. To complete a stream normally,
call Self::flush first; a successful flush leaves the returned
buffer empty.
§Returns
Returns the wrapped writer and pending bytes in logical write order.
Source§impl<W> BufferedBinaryWriter<W, BigEndian>
impl<W> BufferedBinaryWriter<W, BigEndian>
Sourcepub fn write_u128(&mut self, value: u128) -> Result<()>
pub fn write_u128(&mut self, value: u128) -> Result<()>
Sourcepub fn write_i128(&mut self, value: i128) -> Result<()>
pub fn write_i128(&mut self, value: i128) -> Result<()>
Sourcepub fn write_string_with_u16_len(&mut self, value: &str) -> Result<()>
pub fn write_string_with_u16_len(&mut self, value: &str) -> Result<()>
Writes a UTF-8 string prefixed by a u16 byte length.
§Errors
Returns std::io::ErrorKind::InvalidInput when the UTF-8
byte length does not fit u16, or an output error.
Sourcepub fn write_string_with_u32_len(&mut self, value: &str) -> Result<()>
pub fn write_string_with_u32_len(&mut self, value: &str) -> Result<()>
Writes a UTF-8 string prefixed by a u32 byte length.
§Errors
Returns std::io::ErrorKind::InvalidInput when the UTF-8
byte length does not fit u32, or an output error.
Source§impl<W> BufferedBinaryWriter<W, LittleEndian>
impl<W> BufferedBinaryWriter<W, LittleEndian>
Sourcepub fn write_u128(&mut self, value: u128) -> Result<()>
pub fn write_u128(&mut self, value: u128) -> Result<()>
Sourcepub fn write_i128(&mut self, value: i128) -> Result<()>
pub fn write_i128(&mut self, value: i128) -> Result<()>
Sourcepub fn write_string_with_u16_len(&mut self, value: &str) -> Result<()>
pub fn write_string_with_u16_len(&mut self, value: &str) -> Result<()>
Writes a UTF-8 string prefixed by a u16 byte length.
§Errors
Returns std::io::ErrorKind::InvalidInput when the UTF-8
byte length does not fit u16, or an output error.
Sourcepub fn write_string_with_u32_len(&mut self, value: &str) -> Result<()>
pub fn write_string_with_u32_len(&mut self, value: &str) -> Result<()>
Writes a UTF-8 string prefixed by a u32 byte length.
§Errors
Returns std::io::ErrorKind::InvalidInput when the UTF-8
byte length does not fit u32, or an output error.
Source§impl<W> BufferedBinaryWriter<W, NativeEndian>
impl<W> BufferedBinaryWriter<W, NativeEndian>
Sourcepub fn write_u128(&mut self, value: u128) -> Result<()>
pub fn write_u128(&mut self, value: u128) -> Result<()>
Sourcepub fn write_i128(&mut self, value: i128) -> Result<()>
pub fn write_i128(&mut self, value: i128) -> Result<()>
Sourcepub fn write_string_with_u16_len(&mut self, value: &str) -> Result<()>
pub fn write_string_with_u16_len(&mut self, value: &str) -> Result<()>
Writes a UTF-8 string prefixed by a u16 byte length.
§Errors
Returns std::io::ErrorKind::InvalidInput when the UTF-8
byte length does not fit u16, or an output error.
Sourcepub fn write_string_with_u32_len(&mut self, value: &str) -> Result<()>
pub fn write_string_with_u32_len(&mut self, value: &str) -> Result<()>
Writes a UTF-8 string prefixed by a u32 byte length.
§Errors
Returns std::io::ErrorKind::InvalidInput when the UTF-8
byte length does not fit u32, or an output error.
Source§impl<W, O> BufferedBinaryWriter<W, O>
impl<W, O> BufferedBinaryWriter<W, O>
Sourcepub fn is_buffered(&self) -> bool
pub fn is_buffered(&self) -> bool
Returns whether this writer buffers output.
Sourcepub unsafe fn write_unchecked(
&mut self,
input: &[u8],
index: usize,
count: usize,
) -> Result<usize>
pub unsafe fn write_unchecked( &mut self, input: &[u8], index: usize, count: usize, ) -> Result<usize>
Writes up to count bytes from an indexed input range.
§Safety
index..index + count must be a valid range within input.
Sourcepub unsafe fn write_fully_unchecked(
&mut self,
input: &[u8],
index: usize,
count: usize,
) -> Result<()>
pub unsafe fn write_fully_unchecked( &mut self, input: &[u8], index: usize, count: usize, ) -> Result<()>
Writes all bytes from an indexed input range.
§Safety
index..index + count must be a valid range within input.
Sourcepub fn write_fully(&mut self, input: &[u8]) -> Result<()>
pub fn write_fully(&mut self, input: &[u8]) -> Result<()>
Writes all bytes from the full input slice.
Trait Implementations§
Source§impl<W, O> Output for BufferedBinaryWriter<W, O>
impl<W, O> Output for BufferedBinaryWriter<W, O>
Source§fn is_buffered(&self) -> bool
fn is_buffered(&self) -> bool
Source§unsafe fn write_unchecked(
&mut self,
input: &[u8],
index: usize,
count: usize,
) -> Result<usize>
unsafe fn write_unchecked( &mut self, input: &[u8], index: usize, count: usize, ) -> Result<usize>
Writes up to count bytes from an indexed input range.
§Parameters
input: Source slice.index: First source index.count: Maximum number of bytes to write.
§Returns
Returns the number of bytes accepted.
§Errors
Returns an output error encountered while draining pending bytes.
§Safety
index..index + count must be a valid range within input.
Source§fn write(&mut self, input: &[Self::Item]) -> Result<usize, Error>
fn write(&mut self, input: &[Self::Item]) -> Result<usize, Error>
Auto Trait Implementations§
impl<W, O> Freeze for BufferedBinaryWriter<W, O>where
W: Freeze,
impl<W, O> RefUnwindSafe for BufferedBinaryWriter<W, O>where
W: RefUnwindSafe,
impl<W, O> Send for BufferedBinaryWriter<W, O>where
W: Send,
impl<W, O> Sync for BufferedBinaryWriter<W, O>where
W: Sync,
impl<W, O> Unpin for BufferedBinaryWriter<W, O>where
W: Unpin,
impl<W, O> UnsafeUnpin for BufferedBinaryWriter<W, O>where
W: UnsafeUnpin,
impl<W, O> UnwindSafe for BufferedBinaryWriter<W, O>where
W: UnwindSafe,
Blanket Implementations§
Source§impl<W> BinaryWriteExt for W
impl<W> BinaryWriteExt for W
Source§fn write_u16(&mut self, value: u16, byte_order: ByteOrder) -> Result<()>
fn write_u16(&mut self, value: u16, byte_order: ByteOrder) -> Result<()>
Source§fn write_u16_be(&mut self, value: u16) -> Result<()>
fn write_u16_be(&mut self, value: u16) -> Result<()>
Source§fn write_u16_le(&mut self, value: u16) -> Result<()>
fn write_u16_le(&mut self, value: u16) -> Result<()>
Source§fn write_u32(&mut self, value: u32, byte_order: ByteOrder) -> Result<()>
fn write_u32(&mut self, value: u32, byte_order: ByteOrder) -> Result<()>
Source§fn write_u32_be(&mut self, value: u32) -> Result<()>
fn write_u32_be(&mut self, value: u32) -> Result<()>
Source§fn write_u32_le(&mut self, value: u32) -> Result<()>
fn write_u32_le(&mut self, value: u32) -> Result<()>
Source§fn write_u64(&mut self, value: u64, byte_order: ByteOrder) -> Result<()>
fn write_u64(&mut self, value: u64, byte_order: ByteOrder) -> Result<()>
Source§fn write_u64_be(&mut self, value: u64) -> Result<()>
fn write_u64_be(&mut self, value: u64) -> Result<()>
Source§fn write_u64_le(&mut self, value: u64) -> Result<()>
fn write_u64_le(&mut self, value: u64) -> Result<()>
Source§fn write_u128(&mut self, value: u128, byte_order: ByteOrder) -> Result<()>
fn write_u128(&mut self, value: u128, byte_order: ByteOrder) -> Result<()>
Source§fn write_u128_be(&mut self, value: u128) -> Result<()>
fn write_u128_be(&mut self, value: u128) -> Result<()>
Source§fn write_u128_le(&mut self, value: u128) -> Result<()>
fn write_u128_le(&mut self, value: u128) -> Result<()>
Source§fn write_i16(&mut self, value: i16, byte_order: ByteOrder) -> Result<()>
fn write_i16(&mut self, value: i16, byte_order: ByteOrder) -> Result<()>
Source§fn write_i16_be(&mut self, value: i16) -> Result<()>
fn write_i16_be(&mut self, value: i16) -> Result<()>
Source§fn write_i16_le(&mut self, value: i16) -> Result<()>
fn write_i16_le(&mut self, value: i16) -> Result<()>
Source§fn write_i32(&mut self, value: i32, byte_order: ByteOrder) -> Result<()>
fn write_i32(&mut self, value: i32, byte_order: ByteOrder) -> Result<()>
Source§fn write_i32_be(&mut self, value: i32) -> Result<()>
fn write_i32_be(&mut self, value: i32) -> Result<()>
Source§fn write_i32_le(&mut self, value: i32) -> Result<()>
fn write_i32_le(&mut self, value: i32) -> Result<()>
Source§fn write_i64(&mut self, value: i64, byte_order: ByteOrder) -> Result<()>
fn write_i64(&mut self, value: i64, byte_order: ByteOrder) -> Result<()>
Source§fn write_i64_be(&mut self, value: i64) -> Result<()>
fn write_i64_be(&mut self, value: i64) -> Result<()>
Source§fn write_i64_le(&mut self, value: i64) -> Result<()>
fn write_i64_le(&mut self, value: i64) -> Result<()>
Source§fn write_i128(&mut self, value: i128, byte_order: ByteOrder) -> Result<()>
fn write_i128(&mut self, value: i128, byte_order: ByteOrder) -> Result<()>
Source§fn write_i128_be(&mut self, value: i128) -> Result<()>
fn write_i128_be(&mut self, value: i128) -> Result<()>
Source§fn write_i128_le(&mut self, value: i128) -> Result<()>
fn write_i128_le(&mut self, value: i128) -> Result<()>
Source§fn write_f32(&mut self, value: f32, byte_order: ByteOrder) -> Result<()>
fn write_f32(&mut self, value: f32, byte_order: ByteOrder) -> Result<()>
Source§fn write_f32_be(&mut self, value: f32) -> Result<()>
fn write_f32_be(&mut self, value: f32) -> Result<()>
Source§fn write_f32_le(&mut self, value: f32) -> Result<()>
fn write_f32_le(&mut self, value: f32) -> Result<()>
Source§fn write_f64(&mut self, value: f64, byte_order: ByteOrder) -> Result<()>
fn write_f64(&mut self, value: f64, byte_order: ByteOrder) -> Result<()>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<W> Leb128WriteExt for W
impl<W> Leb128WriteExt for W
Source§fn write_uleb_u16(&mut self, value: u16) -> Result<()>
fn write_uleb_u16(&mut self, value: u16) -> Result<()>
u16. Read moreSource§fn write_uleb_u32(&mut self, value: u32) -> Result<()>
fn write_uleb_u32(&mut self, value: u32) -> Result<()>
u32. Read moreSource§fn write_uleb_u64(&mut self, value: u64) -> Result<()>
fn write_uleb_u64(&mut self, value: u64) -> Result<()>
u64. Read moreSource§fn write_uleb_u128(&mut self, value: u128) -> Result<()>
fn write_uleb_u128(&mut self, value: u128) -> Result<()>
u128. Read moreSource§fn write_uleb_usize(&mut self, value: usize) -> Result<()>
fn write_uleb_usize(&mut self, value: usize) -> Result<()>
usize. Read moreSource§impl<T> StringWriteExt for T
impl<T> StringWriteExt for T
Source§fn write_utf8_payload(&mut self, value: &str) -> Result<(), Error>
fn write_utf8_payload(&mut self, value: &str) -> Result<(), Error>
Source§fn write_utf8_string_uleb_usize(&mut self, value: &str) -> Result<(), Error>
fn write_utf8_string_uleb_usize(&mut self, value: &str) -> Result<(), Error>
Source§fn write_utf8_string_uleb_u64(&mut self, value: &str) -> Result<(), Error>
fn write_utf8_string_uleb_u64(&mut self, value: &str) -> Result<(), Error>
u64 byte-length prefix. Read moreSource§fn write_string_with_u16_len(
&mut self,
value: &str,
byte_order: ByteOrder,
) -> Result<(), Error>
fn write_string_with_u16_len( &mut self, value: &str, byte_order: ByteOrder, ) -> Result<(), Error>
u16 byte-length prefix. Read moreSource§fn write_string_with_u16_len_be(&mut self, value: &str) -> Result<(), Error>
fn write_string_with_u16_len_be(&mut self, value: &str) -> Result<(), Error>
u16 byte-length prefix. Read moreSource§fn write_string_with_u16_len_le(&mut self, value: &str) -> Result<(), Error>
fn write_string_with_u16_len_le(&mut self, value: &str) -> Result<(), Error>
u16 byte-length prefix. Read moreSource§fn write_string_with_u32_len(
&mut self,
value: &str,
byte_order: ByteOrder,
) -> Result<(), Error>
fn write_string_with_u32_len( &mut self, value: &str, byte_order: ByteOrder, ) -> Result<(), Error>
u32 byte-length prefix. Read more