Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Crc::digest_with_initial #69

Merged
merged 3 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/crc128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ impl Crc<u128> {
}

pub const fn digest(&self) -> Digest<u128> {
Digest::new(self)
let initial = self.init();
Digest::new(self, initial)
}

pub const fn digest_with_initial(&self, initial: u128) -> Digest<u128> {
Digest::new(self, initial)
}
}

impl<'a> Digest<'a, u128> {
const fn new(crc: &'a Crc<u128>) -> Self {
let value = crc.init();
const fn new(crc: &'a Crc<u128>, value: u128) -> Self {
Digest { crc, value }
}

Expand Down
10 changes: 7 additions & 3 deletions src/crc16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ impl Crc<u16> {
}

pub const fn digest(&self) -> Digest<u16> {
Digest::new(self)
let initial = self.init();
Digest::new(self, initial)
}

pub const fn digest_with_initial(&self, initial: u16) -> Digest<u16> {
Digest::new(self, initial)
}
}

impl<'a> Digest<'a, u16> {
const fn new(crc: &'a Crc<u16>) -> Self {
let value = crc.init();
const fn new(crc: &'a Crc<u16>, value: u16) -> Self {
Digest { crc, value }
}

Expand Down
10 changes: 7 additions & 3 deletions src/crc32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ impl Crc<u32> {
}

pub const fn digest(&self) -> Digest<u32> {
Digest::new(self)
let initial = self.init();
Digest::new(self, initial)
}

pub const fn digest_with_initial(&self, initial: u32) -> Digest<u32> {
Digest::new(self, initial)
}
}

impl<'a> Digest<'a, u32> {
const fn new(crc: &'a Crc<u32>) -> Self {
let value = crc.init();
const fn new(crc: &'a Crc<u32>, value: u32) -> Self {
Digest { crc, value }
}

Expand Down
10 changes: 7 additions & 3 deletions src/crc64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ impl Crc<u64> {
}

pub const fn digest(&self) -> Digest<u64> {
Digest::new(self)
let initial = self.init();
Digest::new(self, initial)
}

pub const fn digest_with_initial(&self, initial: u64) -> Digest<u64> {
Digest::new(self, initial)
}
}

impl<'a> Digest<'a, u64> {
const fn new(crc: &'a Crc<u64>) -> Self {
let value = crc.init();
const fn new(crc: &'a Crc<u64>, value: u64) -> Self {
Digest { crc, value }
}

Expand Down
10 changes: 7 additions & 3 deletions src/crc8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ impl Crc<u8> {
}

pub const fn digest(&self) -> Digest<u8> {
Digest::new(self)
let initial = self.init();
Digest::new(self, initial)
}

pub const fn digest_with_initial(&self, initial: u8) -> Digest<u8> {
voidc marked this conversation as resolved.
Show resolved Hide resolved
Digest::new(self, initial)
}
}

impl<'a> Digest<'a, u8> {
const fn new(crc: &'a Crc<u8>) -> Self {
let value = crc.init();
const fn new(crc: &'a Crc<u8>, value: u8) -> Self {
Digest { crc, value }
}

Expand Down