pub struct HashingWriter<W> { /* private fields */ }Expand description
A bounded caller-owned sink with a raw SHA-256 of successful writes.
Counts and hashes only the bytes reported as accepted by the sink. Short
writes, interrupted writes and byte allowances use BoundedWriter’s
existing contract; Write::write_all handles retries through this wrapper.
Sink errors can have unreported partial effects, which cannot be identified.
Encoding, flush/sync, publication and recovery remain caller-owned.
Accept a complete artifact identity only after the producer/serializer succeeds. Recovering parts after failure describes an observed prefix, not a completed or durable artifact. This wrapper never publishes output.
Implementations§
Source§impl<W> HashingWriter<W>
impl<W> HashingWriter<W>
Sourcepub fn new(writer: W, max_bytes: u64) -> Self
pub fn new(writer: W, max_bytes: u64) -> Self
Select the sink and inclusive allowance for accepted bytes.
Sourcepub const fn bytes_written(&self) -> u64
pub const fn bytes_written(&self) -> u64
Number of bytes reported as accepted by successful writes.
Sourcepub const fn limit_exceeded(&self) -> bool
pub const fn limit_exceeded(&self) -> bool
Whether an offered buffer has exceeded the selected allowance.
Sourcepub fn into_parts(self) -> (W, ArtifactIdentity)
pub fn into_parts(self) -> (W, ArtifactIdentity)
Recover the sink and identity of the observed accepted bytes.
Does not flush, certify producer success or discard partial output. A failed producer must not use this prefix identity to publish an artifact.
Trait Implementations§
Source§impl<W: Write> Write for HashingWriter<W>
impl<W: Write> Write for HashingWriter<W>
Source§fn write(&mut self, buffer: &[u8]) -> Result<usize>
fn write(&mut self, buffer: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)