pub struct Crc32 { /* private fields */ }Expand description
A CRC-32 computed over data that arrives in pieces.
The result does not depend on how the data was split.
§Examples
use compress_lib::checksum::{Crc32, crc32};
let mut crc = Crc32::new();
crc.update(b"1234");
crc.update(b"56789");
assert_eq!(crc.finish(), crc32(b"123456789"));Implementations§
Source§impl Crc32
impl Crc32
Sourcepub const fn from_value(crc: u32, len: u64) -> Self
pub const fn from_value(crc: u32, len: u64) -> Self
Continues from a CRC-32 value already computed over len bytes (for
example, a stored checksum that more data is appended to).
§Examples
use compress_lib::checksum::{Crc32, crc32};
let mut crc = Crc32::from_value(crc32(b"1234"), 4);
crc.update(b"56789");
assert_eq!(crc.finish(), crc32(b"123456789"));Sourcepub fn update(&mut self, data: &[u8])
pub fn update(&mut self, data: &[u8])
Feeds more data.
§Examples
let mut crc = compress_lib::checksum::Crc32::new();
crc.update(b"abc");
assert_eq!(crc.finish(), 0x3524_41C2);Sourcepub const fn finish(&self) -> u32
pub const fn finish(&self) -> u32
The CRC-32 of everything fed so far. Does not reset; more data may follow.
§Examples
let mut crc = compress_lib::checksum::Crc32::new();
crc.update(b"a");
assert_eq!(crc.finish(), 0xE8B7_BE43);Sourcepub const fn len(&self) -> u64
pub const fn len(&self) -> u64
The number of bytes fed so far (wrapping at 2^64).
§Examples
let mut crc = compress_lib::checksum::Crc32::new();
crc.update(b"abc");
assert_eq!(crc.len(), 3);Sourcepub fn combine(&mut self, other: &Crc32)
pub fn combine(&mut self, other: &Crc32)
Appends the checksum of a second piece of data computed separately, as if its bytes had been fed here.
§Examples
use compress_lib::checksum::{Crc32, crc32};
let mut left = Crc32::new();
left.update(b"hello ");
let mut right = Crc32::new();
right.update(b"world");
left.combine(&right);
assert_eq!(left.finish(), crc32(b"hello world"));Trait Implementations§
impl Copy for Crc32
impl Eq for Crc32
impl StructuralPartialEq for Crc32
Auto Trait Implementations§
impl Forget for Crc32
impl Freeze for Crc32
impl RefUnwindSafe for Crc32
impl Send for Crc32
impl Sync for Crc32
impl Unpin for Crc32
impl UnsafeUnpin for Crc32
impl UnwindSafe for Crc32
Blanket Implementations§
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
Mutably borrows from an owned value. Read more