pub struct ChecksumWriter<W, H> { /* private fields */ }Expand description
Writer wrapper that updates a checksum hasher with bytes written.
The wrapped hasher is updated only after the inner writer accepts bytes. Failed writes do not update the hasher.
The checksum value is whatever the supplied Hasher reports. The Rust
standard-library hashers are not specified as stable file formats and are
not cryptographic digests; use this wrapper for stream instrumentation
unless the chosen hasher explicitly documents stronger guarantees.
§Examples
use std::collections::hash_map::DefaultHasher;
use std::hash::Hasher;
use std::io::Write;
use qubit_io::ChecksumWriter;
let mut expected = DefaultHasher::new();
expected.write(b"payload");
let mut writer = ChecksumWriter::new(Vec::new(), DefaultHasher::new());
writer.write_all(b"payload")?;
assert_eq!(expected.finish(), writer.checksum());
assert_eq!(b"payload", writer.get_ref().as_slice());Implementations§
Source§impl<W, H> ChecksumWriter<W, H>where
H: Hasher,
impl<W, H> ChecksumWriter<W, H>where
H: Hasher,
Sourcepub fn hasher_ref(&self) -> &H
pub fn hasher_ref(&self) -> &H
Sourcepub fn hasher_mut(&mut self) -> &mut H
pub fn hasher_mut(&mut self) -> &mut H
Sourcepub fn into_inner(self) -> (W, H)
pub fn into_inner(self) -> (W, H)
Consumes this wrapper and returns the wrapped writer and hasher.
§Returns
A tuple containing the wrapped writer and hasher.
Trait Implementations§
Source§impl<W, H> Seek for ChecksumWriter<W, H>
impl<W, H> Seek for ChecksumWriter<W, H>
Source§fn seek(&mut self, position: SeekFrom) -> Result<u64>
fn seek(&mut self, position: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. Read more
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Rewind to the beginning of a stream. Read more
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
🔬This is a nightly-only experimental API. (
seek_stream_len)Returns the length of this stream (in bytes). Read more
Source§impl<W, H> Write for ChecksumWriter<W, H>
impl<W, H> Write for ChecksumWriter<W, H>
Source§fn write(&mut self, buffer: &[u8]) -> Result<usize>
fn write(&mut self, buffer: &[u8]) -> Result<usize>
Writes a buffer into this writer, returning how many bytes were written. Read more
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flushes this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
write_all_vectored)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations§
impl<W, H> Freeze for ChecksumWriter<W, H>
impl<W, H> RefUnwindSafe for ChecksumWriter<W, H>where
W: RefUnwindSafe,
H: RefUnwindSafe,
impl<W, H> Send for ChecksumWriter<W, H>
impl<W, H> Sync for ChecksumWriter<W, H>
impl<W, H> Unpin for ChecksumWriter<W, H>
impl<W, H> UnsafeUnpin for ChecksumWriter<W, H>where
W: UnsafeUnpin,
H: UnsafeUnpin,
impl<W, H> UnwindSafe for ChecksumWriter<W, H>where
W: UnwindSafe,
H: UnwindSafe,
Blanket Implementations§
Source§impl<T> BinaryWriteExt for T
impl<T> BinaryWriteExt for T
Source§fn write_u16_be(&mut self, value: u16) -> Result<(), Error>
fn write_u16_be(&mut self, value: u16) -> Result<(), Error>
Writes a big-endian
u16. Read moreSource§fn write_u16_le(&mut self, value: u16) -> Result<(), Error>
fn write_u16_le(&mut self, value: u16) -> Result<(), Error>
Writes a little-endian
u16. Read moreSource§fn write_i16_be(&mut self, value: i16) -> Result<(), Error>
fn write_i16_be(&mut self, value: i16) -> Result<(), Error>
Writes a big-endian
i16. Read moreSource§fn write_i16_le(&mut self, value: i16) -> Result<(), Error>
fn write_i16_le(&mut self, value: i16) -> Result<(), Error>
Writes a little-endian
i16. Read moreSource§fn write_u32_be(&mut self, value: u32) -> Result<(), Error>
fn write_u32_be(&mut self, value: u32) -> Result<(), Error>
Writes a big-endian
u32. Read moreSource§fn write_u32_le(&mut self, value: u32) -> Result<(), Error>
fn write_u32_le(&mut self, value: u32) -> Result<(), Error>
Writes a little-endian
u32. Read moreSource§fn write_i32_be(&mut self, value: i32) -> Result<(), Error>
fn write_i32_be(&mut self, value: i32) -> Result<(), Error>
Writes a big-endian
i32. Read moreSource§fn write_i32_le(&mut self, value: i32) -> Result<(), Error>
fn write_i32_le(&mut self, value: i32) -> Result<(), Error>
Writes a little-endian
i32. Read moreSource§fn write_u64_be(&mut self, value: u64) -> Result<(), Error>
fn write_u64_be(&mut self, value: u64) -> Result<(), Error>
Writes a big-endian
u64. Read moreSource§fn write_u64_le(&mut self, value: u64) -> Result<(), Error>
fn write_u64_le(&mut self, value: u64) -> Result<(), Error>
Writes a little-endian
u64. Read moreSource§fn write_i64_be(&mut self, value: i64) -> Result<(), Error>
fn write_i64_be(&mut self, value: i64) -> Result<(), Error>
Writes a big-endian
i64. Read moreSource§fn write_i64_le(&mut self, value: i64) -> Result<(), Error>
fn write_i64_le(&mut self, value: i64) -> Result<(), Error>
Writes a little-endian
i64. Read moreSource§fn write_u128_be(&mut self, value: u128) -> Result<(), Error>
fn write_u128_be(&mut self, value: u128) -> Result<(), Error>
Writes a big-endian
u128. Read moreSource§fn write_u128_le(&mut self, value: u128) -> Result<(), Error>
fn write_u128_le(&mut self, value: u128) -> Result<(), Error>
Writes a little-endian
u128. Read moreSource§fn write_i128_be(&mut self, value: i128) -> Result<(), Error>
fn write_i128_be(&mut self, value: i128) -> Result<(), Error>
Writes a big-endian
i128. Read moreSource§fn write_i128_le(&mut self, value: i128) -> Result<(), Error>
fn write_i128_le(&mut self, value: i128) -> Result<(), Error>
Writes a little-endian
i128. Read moreSource§fn write_f32_be(&mut self, value: f32) -> Result<(), Error>
fn write_f32_be(&mut self, value: f32) -> Result<(), Error>
Writes a big-endian IEEE-754
f32. Read moreSource§fn write_f32_le(&mut self, value: f32) -> Result<(), Error>
fn write_f32_le(&mut self, value: f32) -> Result<(), Error>
Writes a little-endian IEEE-754
f32. Read moreSource§fn write_f64_be(&mut self, value: f64) -> Result<(), Error>
fn write_f64_be(&mut self, value: f64) -> Result<(), Error>
Writes a big-endian IEEE-754
f64. Read moreSource§fn write_f64_le(&mut self, value: f64) -> Result<(), Error>
fn write_f64_le(&mut self, value: f64) -> Result<(), Error>
Writes a little-endian IEEE-754
f64. Read moreSource§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
Mutably borrows from an owned value. Read more
Source§impl<T> Leb128WriteExt for T
impl<T> Leb128WriteExt for T
Source§fn write_uleb_u8(&mut self, value: u8) -> Result<(), Error>
fn write_uleb_u8(&mut self, value: u8) -> Result<(), Error>
Writes an unsigned LEB128
u8. Read moreSource§fn write_uleb_u16(&mut self, value: u16) -> Result<(), Error>
fn write_uleb_u16(&mut self, value: u16) -> Result<(), Error>
Writes an unsigned LEB128
u16. Read moreSource§fn write_uleb_u32(&mut self, value: u32) -> Result<(), Error>
fn write_uleb_u32(&mut self, value: u32) -> Result<(), Error>
Writes an unsigned LEB128
u32. Read moreSource§fn write_uleb_u64(&mut self, value: u64) -> Result<(), Error>
fn write_uleb_u64(&mut self, value: u64) -> Result<(), Error>
Writes an unsigned LEB128
u64. Read moreSource§fn write_uleb_u128(&mut self, value: u128) -> Result<(), Error>
fn write_uleb_u128(&mut self, value: u128) -> Result<(), Error>
Writes an unsigned LEB128
u128. Read moreSource§fn write_uleb_usize(&mut self, value: usize) -> Result<(), Error>
fn write_uleb_usize(&mut self, value: usize) -> Result<(), Error>
Writes an unsigned LEB128
usize. Read moreSource§fn write_sleb_i8(&mut self, value: i8) -> Result<(), Error>
fn write_sleb_i8(&mut self, value: i8) -> Result<(), Error>
Writes a signed LEB128
i8. Read moreSource§fn write_sleb_i16(&mut self, value: i16) -> Result<(), Error>
fn write_sleb_i16(&mut self, value: i16) -> Result<(), Error>
Writes a signed LEB128
i16. Read moreSource§fn write_sleb_i32(&mut self, value: i32) -> Result<(), Error>
fn write_sleb_i32(&mut self, value: i32) -> Result<(), Error>
Writes a signed LEB128
i32. Read moreSource§fn write_sleb_i64(&mut self, value: i64) -> Result<(), Error>
fn write_sleb_i64(&mut self, value: i64) -> Result<(), Error>
Writes a signed LEB128
i64. Read moreSource§impl<T> StringWriteExt for T
impl<T> StringWriteExt for T
Source§fn write_utf8_string_uleb(&mut self, value: &str) -> Result<(), Error>
fn write_utf8_string_uleb(&mut self, value: &str) -> Result<(), Error>
Writes a UTF-8 string with an unsigned LEB128 byte-length prefix. Read more
Source§fn write_utf8_string_u16_be(&mut self, value: &str) -> Result<(), Error>
fn write_utf8_string_u16_be(&mut self, value: &str) -> Result<(), Error>
Writes a UTF-8 string with a big-endian
u16 byte-length prefix. Read moreSource§fn write_utf8_string_u16_le(&mut self, value: &str) -> Result<(), Error>
fn write_utf8_string_u16_le(&mut self, value: &str) -> Result<(), Error>
Writes a UTF-8 string with a little-endian
u16 byte-length prefix. Read moreSource§impl<T> WriteSeekExt for T
impl<T> WriteSeekExt for T
Source§impl<T> ZigZagWriteExt for T
impl<T> ZigZagWriteExt for T
Source§fn write_zigzag_i8(&mut self, value: i8) -> Result<(), Error>
fn write_zigzag_i8(&mut self, value: i8) -> Result<(), Error>
Writes a ZigZag encoded
i8. Read moreSource§fn write_zigzag_i16(&mut self, value: i16) -> Result<(), Error>
fn write_zigzag_i16(&mut self, value: i16) -> Result<(), Error>
Writes a ZigZag encoded
i16. Read moreSource§fn write_zigzag_i32(&mut self, value: i32) -> Result<(), Error>
fn write_zigzag_i32(&mut self, value: i32) -> Result<(), Error>
Writes a ZigZag encoded
i32. Read moreSource§fn write_zigzag_i64(&mut self, value: i64) -> Result<(), Error>
fn write_zigzag_i64(&mut self, value: i64) -> Result<(), Error>
Writes a ZigZag encoded
i64. Read more