Skip to main content

Crc32

Struct Crc32 

Source
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

Source

pub const fn new() -> Self

A CRC-32 over no data yet.

§Examples
assert_eq!(compress_lib::checksum::Crc32::new().finish(), 0);
Source

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"));
Source

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);
Source

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);
Source

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);
Source

pub const fn is_empty(&self) -> bool

true when no data has been fed.

§Examples
assert!(compress_lib::checksum::Crc32::new().is_empty());
Source

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§

Source§

impl Clone for Crc32

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Crc32

Source§

impl Debug for Crc32

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Crc32

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Crc32

Source§

impl Hash for Crc32

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Crc32

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.