mrhooray / crc-rs

Rust implementation of CRC(16, 32, 64) with support of various standards
Apache License 2.0
187 stars 49 forks source link

`Digest` should be Copy #80

Closed lightsing closed 1 year ago

lightsing commented 1 year ago

Digest should dervie Copy.

Usage:

struct ChunkedWriter<I, W> {
    crc: Digest<'static, I>,
    writer: W,
}

impl<I: Implementation, W: io::Write> io::Write for ChunkedWriter<I, W> {
    fn write(&mut self, mut buf: &[u8]) -> io::Result<usize> {
        // some other codes... end of a chunk
        let checksum = self.crc.finalize().to_be_bytes(); // <- cannot move out from a mutable reference
        self.writer.write_all(&checksum)?;
        self.crc = CRC.digest();

        // other...
    }
}
akhilles commented 1 year ago

Can you use std::mem::replace?

lightsing commented 1 year ago

Can you use std::mem::replace?

fine with me. thx.