From 06c5344bb8bbaeb25060106b51ab6fa58f185471 Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Mon, 27 Feb 2023 14:21:47 +0100 Subject: [PATCH 01/13] switch impls based on crate features for u8 as an example --- Cargo.toml | 6 +++++ src/crc8.rs | 8 ++++++- src/crc8/default.rs | 58 +++++++++++++++++++++++++++++++++++++++++---- src/lib.rs | 5 ---- 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 859745c..0089d98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,12 @@ keywords = ["crc", "crc16", "crc32", "crc64", "hash"] categories = ["algorithms", "no-std"] edition = "2018" +[features] +default = ["slice16-defaults"] +notable-defaults = [] +bytewise-defaults = [] +slice16-defaults = [] + [dependencies] crc-catalog = "2.1.0" diff --git a/src/crc8.rs b/src/crc8.rs index 9587e2a..54929c4 100644 --- a/src/crc8.rs +++ b/src/crc8.rs @@ -1,8 +1,14 @@ use crate::util::crc8; use crc_catalog::Algorithm; -mod bytewise; +#[cfg(any( + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" +))] mod default; + +mod bytewise; mod nolookup; mod slice16; diff --git a/src/crc8/default.rs b/src/crc8/default.rs index 2dfec0d..2a2cd18 100644 --- a/src/crc8/default.rs +++ b/src/crc8/default.rs @@ -1,12 +1,45 @@ use crate::crc8::{finalize, init}; -use crate::table::crc8_table_slice_16; +use crate::Implementation; use crate::{Algorithm, Crc, Digest}; -use super::update_slice16; +#[cfg(feature = "notable-defaults")] +impl Implementation for u8 { + type Width = u8; + type Table = (); +} + +#[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] +impl Implementation for u8 { + type Width = u8; + type Table = [u8; 256]; +} + +#[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" +))] +impl Implementation for u8 { + type Width = u8; + type Table = [[u8; 256]; 16]; +} impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { - let table = crc8_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + let table = + crate::table::crc8_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); + + #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + let table = crate::table::crc8_table(algorithm.width, algorithm.poly, algorithm.refin); + + #[cfg(feature = "notable-defaults")] + let table = (); + Self { algorithm, table } } @@ -17,7 +50,24 @@ impl Crc { } const fn update(&self, crc: u8, bytes: &[u8]) -> u8 { - update_slice16(crc, &self.table, bytes) + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + { + super::update_slice16(crc, &self.table, bytes) + } + + #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + { + super::update_bytewise(crc, &self.table, bytes) + } + + #[cfg(feature = "notable-defaults")] + { + super::update_nolookup(crc, self.algorithm, bytes) + } } pub const fn digest(&self) -> Digest { diff --git a/src/lib.rs b/src/lib.rs index ff16aa9..ac29a14 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,11 +76,6 @@ pub trait Implementation: private::Sealed { type Table; } -impl Implementation for u8 { - type Width = u8; - type Table = [[u8; 256]; 16]; -} - impl Implementation for u16 { type Width = u16; type Table = [[u16; 256]; 16]; From c7f7f734d106ae2973b7eb3534b5e94e6e23a653 Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Sat, 8 Apr 2023 21:41:36 +0200 Subject: [PATCH 02/13] switch impls based on crate features for u16 --- src/crc16.rs | 8 +++++- src/crc16/default.rs | 58 +++++++++++++++++++++++++++++++++++++++++--- src/lib.rs | 5 ---- 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/crc16.rs b/src/crc16.rs index bb31de8..d3dd525 100644 --- a/src/crc16.rs +++ b/src/crc16.rs @@ -1,8 +1,14 @@ use crate::util::crc16; use crc_catalog::Algorithm; -mod bytewise; +#[cfg(any( + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" +))] mod default; + +mod bytewise; mod nolookup; mod slice16; diff --git a/src/crc16/default.rs b/src/crc16/default.rs index 75123d1..df6c961 100644 --- a/src/crc16/default.rs +++ b/src/crc16/default.rs @@ -1,12 +1,45 @@ use crate::crc16::{finalize, init}; -use crate::table::crc16_table_slice_16; +use crate::Implementation; use crate::{Algorithm, Crc, Digest}; -use super::update_slice16; +#[cfg(feature = "notable-defaults")] +impl Implementation for u16 { + type Width = u16; + type Table = (); +} + +#[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] +impl Implementation for u16 { + type Width = u16; + type Table = [u16; 256]; +} + +#[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" +))] +impl Implementation for u16 { + type Width = u16; + type Table = [[u16; 256]; 16]; +} impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { - let table = crc16_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + let table = + crate::table::crc16_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); + + #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + let table = crate::table::crc16_table(algorithm.width, algorithm.poly, algorithm.refin); + + #[cfg(feature = "notable-defaults")] + let table = (); + Self { algorithm, table } } @@ -17,7 +50,24 @@ impl Crc { } const fn update(&self, crc: u16, bytes: &[u8]) -> u16 { - update_slice16(crc, self.algorithm.refin, &self.table, bytes) + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + { + super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) + } + + #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + { + super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) + } + + #[cfg(feature = "notable-defaults")] + { + super::update_nolookup(crc, self.algorithm, bytes) + } } pub const fn digest(&self) -> Digest { diff --git a/src/lib.rs b/src/lib.rs index ac29a14..656bf50 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,11 +76,6 @@ pub trait Implementation: private::Sealed { type Table; } -impl Implementation for u16 { - type Width = u16; - type Table = [[u16; 256]; 16]; -} - impl Implementation for u32 { type Width = u32; type Table = [[u32; 256]; 16]; From e584dd54652c1f45cb1f467d204f73447f5774e9 Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Sat, 8 Apr 2023 21:46:14 +0200 Subject: [PATCH 03/13] switch impls based on crate features for u32 --- src/crc32.rs | 8 +++++- src/crc32/default.rs | 60 ++++++++++++++++++++++++++++++++++++++++---- src/lib.rs | 5 ---- 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/crc32.rs b/src/crc32.rs index 063814f..43af499 100644 --- a/src/crc32.rs +++ b/src/crc32.rs @@ -1,5 +1,11 @@ -mod bytewise; +#[cfg(any( + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" +))] mod default; + +mod bytewise; mod nolookup; mod slice16; diff --git a/src/crc32/default.rs b/src/crc32/default.rs index c35e3be..c51733d 100644 --- a/src/crc32/default.rs +++ b/src/crc32/default.rs @@ -1,11 +1,44 @@ -use crate::table::crc32_table_slice_16; -use crate::{Algorithm, Crc, Digest}; +use crate::{Algorithm, Crc, Digest, Implementation}; -use super::{finalize, init, update_slice16}; +use super::{finalize, init}; + +#[cfg(feature = "notable-defaults")] +impl Implementation for u32 { + type Width = u32; + type Table = (); +} + +#[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] +impl Implementation for u32 { + type Width = u32; + type Table = [u32; 256]; +} + +#[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" +))] +impl Implementation for u32 { + type Width = u32; + type Table = [[u32; 256]; 16]; +} impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { - let table = crc32_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + let table = + crate::table::crc32_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); + + #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + let table = crate::table::crc32_table(algorithm.width, algorithm.poly, algorithm.refin); + + #[cfg(feature = "notable-defaults")] + let table = (); Self { algorithm, table } } @@ -16,7 +49,24 @@ impl Crc { } const fn update(&self, crc: u32, bytes: &[u8]) -> u32 { - update_slice16(crc, self.algorithm.refin, &self.table, bytes) + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + { + super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) + } + + #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + { + super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) + } + + #[cfg(feature = "notable-defaults")] + { + super::update_nolookup(crc, self.algorithm, bytes) + } } pub const fn digest(&self) -> Digest { diff --git a/src/lib.rs b/src/lib.rs index 656bf50..7a2c762 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,11 +76,6 @@ pub trait Implementation: private::Sealed { type Table; } -impl Implementation for u32 { - type Width = u32; - type Table = [[u32; 256]; 16]; -} - impl Implementation for u64 { type Width = u64; type Table = [[u64; 256]; 16]; From 9d24c8641c263999ab80e8310316cf57482293ac Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Sat, 8 Apr 2023 21:48:50 +0200 Subject: [PATCH 04/13] switch impls based on crate features for u64 --- src/crc64.rs | 8 +++++- src/crc64/default.rs | 60 ++++++++++++++++++++++++++++++++++++++++---- src/lib.rs | 5 ---- 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/crc64.rs b/src/crc64.rs index b2ff118..dcc8dbf 100644 --- a/src/crc64.rs +++ b/src/crc64.rs @@ -2,8 +2,14 @@ use crc_catalog::Algorithm; use crate::util::crc64; -mod bytewise; +#[cfg(any( + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" +))] mod default; + +mod bytewise; mod nolookup; mod slice16; diff --git a/src/crc64/default.rs b/src/crc64/default.rs index 73628ef..3dab53d 100644 --- a/src/crc64/default.rs +++ b/src/crc64/default.rs @@ -1,11 +1,44 @@ -use crate::table::crc64_table_slice_16; -use crate::{Algorithm, Crc, Digest}; +use crate::{Algorithm, Crc, Digest, Implementation}; -use super::{finalize, init, update_slice16}; +use super::{finalize, init}; + +#[cfg(feature = "notable-defaults")] +impl Implementation for u64 { + type Width = u64; + type Table = (); +} + +#[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] +impl Implementation for u64 { + type Width = u64; + type Table = [u64; 256]; +} + +#[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" +))] +impl Implementation for u64 { + type Width = u64; + type Table = [[u64; 256]; 16]; +} impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { - let table = crc64_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + let table = + crate::table::crc64_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); + + #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + let table = crate::table::crc64_table(algorithm.width, algorithm.poly, algorithm.refin); + + #[cfg(feature = "notable-defaults")] + let table = (); Self { algorithm, table } } @@ -16,7 +49,24 @@ impl Crc { } const fn update(&self, crc: u64, bytes: &[u8]) -> u64 { - update_slice16(crc, self.algorithm.refin, &self.table, bytes) + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + { + super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) + } + + #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + { + super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) + } + + #[cfg(feature = "notable-defaults")] + { + super::update_nolookup(crc, self.algorithm, bytes) + } } pub const fn digest(&self) -> Digest { diff --git a/src/lib.rs b/src/lib.rs index 7a2c762..7126631 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,11 +76,6 @@ pub trait Implementation: private::Sealed { type Table; } -impl Implementation for u64 { - type Width = u64; - type Table = [[u64; 256]; 16]; -} - impl Implementation for u128 { type Width = u128; type Table = [u128; 256]; From 2b77d4d7b6495c5dea75765412a444971ae9bba3 Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Sat, 8 Apr 2023 21:51:03 +0200 Subject: [PATCH 05/13] switch impls based on crate features for u128 --- src/crc128.rs | 8 +++++- src/crc128/default.rs | 60 +++++++++++++++++++++++++++++++++++++++---- src/lib.rs | 5 ---- 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/crc128.rs b/src/crc128.rs index 11c77e2..12d98e0 100644 --- a/src/crc128.rs +++ b/src/crc128.rs @@ -2,8 +2,14 @@ use crc_catalog::Algorithm; use crate::util::crc128; -mod bytewise; +#[cfg(any( + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" +))] mod default; + +mod bytewise; mod nolookup; mod slice16; diff --git a/src/crc128/default.rs b/src/crc128/default.rs index d8d4be9..a20d11b 100644 --- a/src/crc128/default.rs +++ b/src/crc128/default.rs @@ -1,11 +1,44 @@ -use crate::table::crc128_table; -use crate::{Algorithm, Crc, Digest}; +use crate::{Algorithm, Crc, Digest, Implementation}; -use super::{finalize, init, update_bytewise}; +use super::{finalize, init}; + +#[cfg(feature = "notable-defaults")] +impl Implementation for u128 { + type Width = u128; + type Table = (); +} + +#[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] +impl Implementation for u128 { + type Width = u128; + type Table = [u128; 256]; +} + +#[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" +))] +impl Implementation for u128 { + type Width = u128; + type Table = [[u128; 256]; 16]; +} impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { - let table = crc128_table(algorithm.width, algorithm.poly, algorithm.refin); + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + let table = + crate::table::crc128_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); + + #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + let table = crate::table::crc128_table(algorithm.width, algorithm.poly, algorithm.refin); + + #[cfg(feature = "notable-defaults")] + let table = (); Self { algorithm, table } } @@ -16,7 +49,24 @@ impl Crc { } const fn update(&self, crc: u128, bytes: &[u8]) -> u128 { - update_bytewise(crc, self.algorithm.refin, &self.table, bytes) + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + { + super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) + } + + #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + { + super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) + } + + #[cfg(feature = "notable-defaults")] + { + super::update_nolookup(crc, self.algorithm, bytes) + } } pub const fn digest(&self) -> Digest { diff --git a/src/lib.rs b/src/lib.rs index 7126631..d0a4ded 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,11 +76,6 @@ pub trait Implementation: private::Sealed { type Table; } -impl Implementation for u128 { - type Width = u128; - type Table = [u128; 256]; -} - /// Crc with pluggable implementations ([Nolookup], [Bytewise], [Slice16]). /// To choose the default implementation, use the [Width] directly (e.g. `Crc`). pub struct Crc { From 91f1e99458f94b4ff2456047be435e2cdf8c2764 Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Sun, 9 Apr 2023 09:23:44 +0200 Subject: [PATCH 06/13] if no feature is selected use the bytewise implementation --- Cargo.toml | 1 - src/crc128.rs | 11 ++--------- src/crc128/default.rs | 31 +++++++++++++++++++++++++++++-- src/crc16.rs | 8 +------- src/crc16/default.rs | 30 ++++++++++++++++++++++++++++-- src/crc32.rs | 12 +++--------- src/crc32/default.rs | 31 +++++++++++++++++++++++++++++-- src/crc64.rs | 11 ++--------- src/crc64/default.rs | 31 +++++++++++++++++++++++++++++-- src/crc8.rs | 8 +------- src/crc8/default.rs | 30 ++++++++++++++++++++++++++++-- 11 files changed, 152 insertions(+), 52 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0089d98..4265671 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ categories = ["algorithms", "no-std"] edition = "2018" [features] -default = ["slice16-defaults"] notable-defaults = [] bytewise-defaults = [] slice16-defaults = [] diff --git a/src/crc128.rs b/src/crc128.rs index 12d98e0..ecf33ee 100644 --- a/src/crc128.rs +++ b/src/crc128.rs @@ -1,15 +1,8 @@ -use crc_catalog::Algorithm; - use crate::util::crc128; - -#[cfg(any( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" -))] -mod default; +use crc_catalog::Algorithm; mod bytewise; +mod default; mod nolookup; mod slice16; diff --git a/src/crc128/default.rs b/src/crc128/default.rs index a20d11b..d4d71dc 100644 --- a/src/crc128/default.rs +++ b/src/crc128/default.rs @@ -1,7 +1,6 @@ +use crate::crc128::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -use super::{finalize, init}; - #[cfg(feature = "notable-defaults")] impl Implementation for u128 { type Width = u128; @@ -24,6 +23,16 @@ impl Implementation for u128 { type Table = [[u128; 256]; 16]; } +#[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") +))] +impl Implementation for u128 { + type Width = u128; + type Table = [u128; 256]; +} + impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( @@ -38,7 +47,16 @@ impl Crc { let table = crate::table::crc128_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "notable-defaults")] + #[allow(clippy::let_unit_value)] let table = (); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + let table = crate::table::crc128_table(algorithm.width, algorithm.poly, algorithm.refin); + Self { algorithm, table } } @@ -67,6 +85,15 @@ impl Crc { { super::update_nolookup(crc, self.algorithm, bytes) } + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + { + super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) + } } pub const fn digest(&self) -> Digest { diff --git a/src/crc16.rs b/src/crc16.rs index d3dd525..bb31de8 100644 --- a/src/crc16.rs +++ b/src/crc16.rs @@ -1,14 +1,8 @@ use crate::util::crc16; use crc_catalog::Algorithm; -#[cfg(any( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" -))] -mod default; - mod bytewise; +mod default; mod nolookup; mod slice16; diff --git a/src/crc16/default.rs b/src/crc16/default.rs index df6c961..01fceac 100644 --- a/src/crc16/default.rs +++ b/src/crc16/default.rs @@ -1,6 +1,5 @@ use crate::crc16::{finalize, init}; -use crate::Implementation; -use crate::{Algorithm, Crc, Digest}; +use crate::{Algorithm, Crc, Digest, Implementation}; #[cfg(feature = "notable-defaults")] impl Implementation for u16 { @@ -24,6 +23,16 @@ impl Implementation for u16 { type Table = [[u16; 256]; 16]; } +#[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") +))] +impl Implementation for u16 { + type Width = u16; + type Table = [u16; 256]; +} + impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( @@ -38,8 +47,16 @@ impl Crc { let table = crate::table::crc16_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "notable-defaults")] + #[allow(clippy::let_unit_value)] let table = (); + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + let table = crate::table::crc16_table(algorithm.width, algorithm.poly, algorithm.refin); + Self { algorithm, table } } @@ -68,6 +85,15 @@ impl Crc { { super::update_nolookup(crc, self.algorithm, bytes) } + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + { + super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) + } } pub const fn digest(&self) -> Digest { diff --git a/src/crc32.rs b/src/crc32.rs index 43af499..1c0d46f 100644 --- a/src/crc32.rs +++ b/src/crc32.rs @@ -1,17 +1,11 @@ -#[cfg(any( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" -))] -mod default; +use crate::util::crc32; +use crc_catalog::Algorithm; mod bytewise; +mod default; mod nolookup; mod slice16; -use crate::util::crc32; -use crc_catalog::Algorithm; - // init is shared between all impls const fn init(algorithm: &Algorithm, initial: u32) -> u32 { if algorithm.refin { diff --git a/src/crc32/default.rs b/src/crc32/default.rs index c51733d..0c0eed0 100644 --- a/src/crc32/default.rs +++ b/src/crc32/default.rs @@ -1,7 +1,6 @@ +use crate::crc32::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -use super::{finalize, init}; - #[cfg(feature = "notable-defaults")] impl Implementation for u32 { type Width = u32; @@ -24,6 +23,16 @@ impl Implementation for u32 { type Table = [[u32; 256]; 16]; } +#[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") +))] +impl Implementation for u32 { + type Width = u32; + type Table = [u32; 256]; +} + impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( @@ -38,7 +47,16 @@ impl Crc { let table = crate::table::crc32_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "notable-defaults")] + #[allow(clippy::let_unit_value)] let table = (); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + let table = crate::table::crc32_table(algorithm.width, algorithm.poly, algorithm.refin); + Self { algorithm, table } } @@ -67,6 +85,15 @@ impl Crc { { super::update_nolookup(crc, self.algorithm, bytes) } + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + { + super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) + } } pub const fn digest(&self) -> Digest { diff --git a/src/crc64.rs b/src/crc64.rs index dcc8dbf..aac36ac 100644 --- a/src/crc64.rs +++ b/src/crc64.rs @@ -1,15 +1,8 @@ -use crc_catalog::Algorithm; - use crate::util::crc64; - -#[cfg(any( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" -))] -mod default; +use crc_catalog::Algorithm; mod bytewise; +mod default; mod nolookup; mod slice16; diff --git a/src/crc64/default.rs b/src/crc64/default.rs index 3dab53d..6f3263e 100644 --- a/src/crc64/default.rs +++ b/src/crc64/default.rs @@ -1,7 +1,6 @@ +use crate::crc64::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -use super::{finalize, init}; - #[cfg(feature = "notable-defaults")] impl Implementation for u64 { type Width = u64; @@ -24,6 +23,16 @@ impl Implementation for u64 { type Table = [[u64; 256]; 16]; } +#[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") +))] +impl Implementation for u64 { + type Width = u64; + type Table = [u64; 256]; +} + impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( @@ -38,7 +47,16 @@ impl Crc { let table = crate::table::crc64_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "notable-defaults")] + #[allow(clippy::let_unit_value)] let table = (); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + let table = crate::table::crc64_table(algorithm.width, algorithm.poly, algorithm.refin); + Self { algorithm, table } } @@ -67,6 +85,15 @@ impl Crc { { super::update_nolookup(crc, self.algorithm, bytes) } + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + { + super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) + } } pub const fn digest(&self) -> Digest { diff --git a/src/crc8.rs b/src/crc8.rs index 54929c4..9587e2a 100644 --- a/src/crc8.rs +++ b/src/crc8.rs @@ -1,14 +1,8 @@ use crate::util::crc8; use crc_catalog::Algorithm; -#[cfg(any( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" -))] -mod default; - mod bytewise; +mod default; mod nolookup; mod slice16; diff --git a/src/crc8/default.rs b/src/crc8/default.rs index 2a2cd18..7e43e31 100644 --- a/src/crc8/default.rs +++ b/src/crc8/default.rs @@ -1,6 +1,5 @@ use crate::crc8::{finalize, init}; -use crate::Implementation; -use crate::{Algorithm, Crc, Digest}; +use crate::{Algorithm, Crc, Digest, Implementation}; #[cfg(feature = "notable-defaults")] impl Implementation for u8 { @@ -24,6 +23,16 @@ impl Implementation for u8 { type Table = [[u8; 256]; 16]; } +#[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") +))] +impl Implementation for u8 { + type Width = u8; + type Table = [u8; 256]; +} + impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( @@ -38,8 +47,16 @@ impl Crc { let table = crate::table::crc8_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "notable-defaults")] + #[allow(clippy::let_unit_value)] let table = (); + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + let table = crate::table::crc8_table(algorithm.width, algorithm.poly, algorithm.refin); + Self { algorithm, table } } @@ -68,6 +85,15 @@ impl Crc { { super::update_nolookup(crc, self.algorithm, bytes) } + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + { + super::update_bytewise(crc, &self.table, bytes) + } } pub const fn digest(&self) -> Digest { From 92001565ad8306e2efe5c6186ed39b3d3791ae65 Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Wed, 12 Apr 2023 11:34:29 +0200 Subject: [PATCH 07/13] add tests for the sizes of the default implementation under the various combinations of the features --- src/crc128.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/crc16.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/crc32.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/crc64.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/crc8.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 285 insertions(+), 5 deletions(-) diff --git a/src/crc128.rs b/src/crc128.rs index ecf33ee..20e352b 100644 --- a/src/crc128.rs +++ b/src/crc128.rs @@ -169,9 +169,65 @@ const fn update_slice16( #[cfg(test)] mod test { - use crate::{Bytewise, Crc, NoTable, Slice16}; + use crate::{Bytewise, Crc, Implementation, NoTable, Slice16}; use crc_catalog::{Algorithm, CRC_82_DARC}; + #[test] + fn default_table_size() { + let table_size = core::mem::size_of::<::Table>(); + #[cfg(all( + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + feature = "bytewise-defaults", + not(feature = "slice16-defaults") + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + assert_eq!(0, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))] + assert_eq!(256 * 16, table_size); + #[cfg(all( + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + not(feature = "slice16-defaults") + ))] + assert_eq!(256 * 16, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + assert_eq!(256 * 16 * 16, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + assert_eq!(256 * 16, table_size); + } + /// Test this opitimized version against the well known implementation to ensure correctness #[test] fn correctness() { diff --git a/src/crc16.rs b/src/crc16.rs index bb31de8..b7b7621 100644 --- a/src/crc16.rs +++ b/src/crc16.rs @@ -141,9 +141,65 @@ const fn update_slice16( #[cfg(test)] mod test { - use crate::{Bytewise, Crc, NoTable, Slice16}; + use crate::{Bytewise, Crc, Implementation, NoTable, Slice16}; use crc_catalog::{Algorithm, CRC_16_IBM_SDLC}; + #[test] + fn default_table_size() { + let table_size = core::mem::size_of::<::Table>(); + #[cfg(all( + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + feature = "bytewise-defaults", + not(feature = "slice16-defaults") + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + assert_eq!(0, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))] + assert_eq!(256 * 2, table_size); + #[cfg(all( + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + not(feature = "slice16-defaults") + ))] + assert_eq!(256 * 2, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + assert_eq!(256 * 16 * 2, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + assert_eq!(256 * 2, table_size); + } + /// Test this opitimized version against the well known implementation to ensure correctness #[test] fn correctness() { diff --git a/src/crc32.rs b/src/crc32.rs index 1c0d46f..1b83779 100644 --- a/src/crc32.rs +++ b/src/crc32.rs @@ -152,9 +152,65 @@ const fn update_slice16( #[cfg(test)] mod test { - use crate::{Bytewise, Crc, NoTable, Slice16}; + use crate::{Bytewise, Crc, Implementation, NoTable, Slice16}; use crc_catalog::{Algorithm, CRC_32_ISCSI}; + #[test] + fn default_table_size() { + let table_size = core::mem::size_of::<::Table>(); + #[cfg(all( + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + feature = "bytewise-defaults", + not(feature = "slice16-defaults") + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + assert_eq!(0, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))] + assert_eq!(256 * 4, table_size); + #[cfg(all( + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + not(feature = "slice16-defaults") + ))] + assert_eq!(256 * 4, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + assert_eq!(256 * 16 * 4, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + assert_eq!(256 * 4, table_size); + } + /// Test this opitimized version against the well known implementation to ensure correctness #[test] fn correctness() { diff --git a/src/crc64.rs b/src/crc64.rs index aac36ac..df16f14 100644 --- a/src/crc64.rs +++ b/src/crc64.rs @@ -154,9 +154,65 @@ const fn update_slice16( #[cfg(test)] mod test { - use crate::{Bytewise, Crc, NoTable, Slice16}; + use crate::{Bytewise, Crc, Implementation, NoTable, Slice16}; use crc_catalog::{Algorithm, CRC_64_ECMA_182}; + #[test] + fn default_table_size() { + let table_size = core::mem::size_of::<::Table>(); + #[cfg(all( + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + feature = "bytewise-defaults", + not(feature = "slice16-defaults") + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + assert_eq!(0, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))] + assert_eq!(256 * 8, table_size); + #[cfg(all( + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + not(feature = "slice16-defaults") + ))] + assert_eq!(256 * 8, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + assert_eq!(256 * 16 * 8, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + assert_eq!(256 * 8, table_size); + } + /// Test this opitimized version against the well known implementation to ensure correctness #[test] fn correctness() { diff --git a/src/crc8.rs b/src/crc8.rs index 9587e2a..8326708 100644 --- a/src/crc8.rs +++ b/src/crc8.rs @@ -88,9 +88,65 @@ const fn update_slice16(mut crc: u8, table: &[[u8; 256]; 16], bytes: &[u8]) -> u #[cfg(test)] mod test { - use crate::{Bytewise, Crc, NoTable, Slice16}; + use crate::{Bytewise, Crc, Implementation, NoTable, Slice16}; use crc_catalog::{Algorithm, CRC_8_BLUETOOTH}; + #[test] + fn default_table_size() { + let table_size = core::mem::size_of::<::Table>(); + #[cfg(all( + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + feature = "bytewise-defaults", + not(feature = "slice16-defaults") + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + assert_eq!(0, table_size); + #[cfg(all( + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + assert_eq!(0, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))] + assert_eq!(256 * 1, table_size); + #[cfg(all( + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + not(feature = "slice16-defaults") + ))] + assert_eq!(256 * 1, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" + ))] + assert_eq!(256 * 16 * 1, table_size); + + #[cfg(all( + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") + ))] + assert_eq!(256 * 1, table_size); + } + /// Test this opitimized version against the well known implementation to ensure correctness #[test] fn correctness() { From 943ef4da0190bf94b9b9a7da4cc2e11cc28895a4 Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Wed, 12 Apr 2023 11:47:46 +0200 Subject: [PATCH 08/13] add script that runs the tests under all feature combinations --- tests/test_under_all_feature_combinations.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 tests/test_under_all_feature_combinations.sh diff --git a/tests/test_under_all_feature_combinations.sh b/tests/test_under_all_feature_combinations.sh new file mode 100755 index 0000000..b476f2c --- /dev/null +++ b/tests/test_under_all_feature_combinations.sh @@ -0,0 +1,15 @@ +set -ex + +cargo test +cargo test --no-default-features + +cargo test --features slice16-defaults +cargo test --features bytewise-defaults +cargo test --features notable-defaults + +cargo test --features bytewise-defaults,slice16-defaults +cargo test --features notable-defaults,bytewise-defaults +cargo test --features notable-defaults,slice16-defaults + +cargo test --features notable-defaults,bytewise-defaults,slice16-defaults + From 8bc54347768494568cf0e5ced6512535fe9f9743 Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Mon, 17 Apr 2023 13:08:19 +0200 Subject: [PATCH 09/13] make size tests fail on compilation --- src/crc128.rs | 102 +++++++++++++++++++++++++++++++++----------------- src/crc16.rs | 102 +++++++++++++++++++++++++++++++++----------------- src/crc32.rs | 102 +++++++++++++++++++++++++++++++++----------------- src/crc64.rs | 102 +++++++++++++++++++++++++++++++++----------------- src/crc8.rs | 102 +++++++++++++++++++++++++++++++++----------------- 5 files changed, 340 insertions(+), 170 deletions(-) diff --git a/src/crc128.rs b/src/crc128.rs index 20e352b..104afa4 100644 --- a/src/crc128.rs +++ b/src/crc128.rs @@ -174,58 +174,92 @@ mod test { #[test] fn default_table_size() { - let table_size = core::mem::size_of::<::Table>(); + const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); + const BYTES_PER_ENTRY: usize = 16; #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" - ))] - assert_eq!(0, table_size); + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))]{ + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + feature = "notable-defaults", + feature = "bytewise-defaults", + not(feature = "slice16-defaults") ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - feature = "slice16-defaults" + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + feature = "slice16-defaults" ))] - assert_eq!(256 * 16, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + not(feature = "slice16-defaults") ))] - assert_eq!(256 * 16, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" ))] - assert_eq!(256 * 16 * 16, table_size); + { + const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") ))] - assert_eq!(256 * 16, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } + let _ = TABLE_SIZE; + let _ = BYTES_PER_ENTRY; } /// Test this opitimized version against the well known implementation to ensure correctness diff --git a/src/crc16.rs b/src/crc16.rs index b7b7621..aa3a5a8 100644 --- a/src/crc16.rs +++ b/src/crc16.rs @@ -146,58 +146,92 @@ mod test { #[test] fn default_table_size() { - let table_size = core::mem::size_of::<::Table>(); + const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); + const BYTES_PER_ENTRY: usize = 2; #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" - ))] - assert_eq!(0, table_size); + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))]{ + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + feature = "notable-defaults", + feature = "bytewise-defaults", + not(feature = "slice16-defaults") ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - feature = "slice16-defaults" + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + feature = "slice16-defaults" ))] - assert_eq!(256 * 2, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + not(feature = "slice16-defaults") ))] - assert_eq!(256 * 2, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" ))] - assert_eq!(256 * 16 * 2, table_size); + { + const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") ))] - assert_eq!(256 * 2, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } + let _ = TABLE_SIZE; + let _ = BYTES_PER_ENTRY; } /// Test this opitimized version against the well known implementation to ensure correctness diff --git a/src/crc32.rs b/src/crc32.rs index 1b83779..4533dbe 100644 --- a/src/crc32.rs +++ b/src/crc32.rs @@ -157,58 +157,92 @@ mod test { #[test] fn default_table_size() { - let table_size = core::mem::size_of::<::Table>(); + const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); + const BYTES_PER_ENTRY: usize = 4; #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" - ))] - assert_eq!(0, table_size); + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))]{ + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + feature = "notable-defaults", + feature = "bytewise-defaults", + not(feature = "slice16-defaults") ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - feature = "slice16-defaults" + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + feature = "slice16-defaults" ))] - assert_eq!(256 * 4, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + not(feature = "slice16-defaults") ))] - assert_eq!(256 * 4, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" ))] - assert_eq!(256 * 16 * 4, table_size); + { + const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") ))] - assert_eq!(256 * 4, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } + let _ = TABLE_SIZE; + let _ = BYTES_PER_ENTRY; } /// Test this opitimized version against the well known implementation to ensure correctness diff --git a/src/crc64.rs b/src/crc64.rs index df16f14..8248c57 100644 --- a/src/crc64.rs +++ b/src/crc64.rs @@ -159,58 +159,92 @@ mod test { #[test] fn default_table_size() { - let table_size = core::mem::size_of::<::Table>(); + const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); + const BYTES_PER_ENTRY: usize = 8; #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" - ))] - assert_eq!(0, table_size); + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))]{ + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + feature = "notable-defaults", + feature = "bytewise-defaults", + not(feature = "slice16-defaults") ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - feature = "slice16-defaults" + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + feature = "slice16-defaults" ))] - assert_eq!(256 * 8, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + not(feature = "slice16-defaults") ))] - assert_eq!(256 * 8, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" ))] - assert_eq!(256 * 16 * 8, table_size); + { + const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") ))] - assert_eq!(256 * 8, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } + let _ = TABLE_SIZE; + let _ = BYTES_PER_ENTRY; } /// Test this opitimized version against the well known implementation to ensure correctness diff --git a/src/crc8.rs b/src/crc8.rs index 8326708..7b7ba5d 100644 --- a/src/crc8.rs +++ b/src/crc8.rs @@ -93,58 +93,92 @@ mod test { #[test] fn default_table_size() { - let table_size = core::mem::size_of::<::Table>(); + const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); + const BYTES_PER_ENTRY: usize = 1; #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" - ))] - assert_eq!(0, table_size); + feature = "notable-defaults", + feature = "bytewise-defaults", + feature = "slice16-defaults" + ))]{ + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + feature = "notable-defaults", + feature = "bytewise-defaults", + not(feature = "slice16-defaults") ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + feature = "notable-defaults", + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") ))] - assert_eq!(0, table_size); + { + const EXPECTED: usize = 0; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - feature = "slice16-defaults" + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + feature = "slice16-defaults" ))] - assert_eq!(256 * 1, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + not(feature = "notable-defaults"), + feature = "bytewise-defaults", + not(feature = "slice16-defaults") ))] - assert_eq!(256 * 1, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + feature = "slice16-defaults" ))] - assert_eq!(256 * 16 * 1, table_size); + { + const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "notable-defaults"), + not(feature = "bytewise-defaults"), + not(feature = "slice16-defaults") ))] - assert_eq!(256 * 1, table_size); + { + const EXPECTED: usize = 256 * BYTES_PER_ENTRY; + let _ = EXPECTED; + const _: () = assert!(EXPECTED == TABLE_SIZE); + } + let _ = TABLE_SIZE; + let _ = BYTES_PER_ENTRY; } /// Test this opitimized version against the well known implementation to ensure correctness From d337ce505b81cf70256b8b60d850fba42acf1cc0 Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Mon, 17 Apr 2023 13:25:14 +0200 Subject: [PATCH 10/13] rename the features to reflect their effects better and avoid the word default --- Cargo.toml | 12 +++-- src/crc128.rs | 50 ++++++++++---------- src/crc128/default.rs | 48 +++++++++---------- src/crc16.rs | 50 ++++++++++---------- src/crc16/default.rs | 48 +++++++++---------- src/crc32.rs | 50 ++++++++++---------- src/crc32/default.rs | 48 +++++++++---------- src/crc64.rs | 50 ++++++++++---------- src/crc64/default.rs | 48 +++++++++---------- src/crc8.rs | 50 ++++++++++---------- src/crc8/default.rs | 48 +++++++++---------- tests/test_under_all_feature_combinations.sh | 14 +++--- 12 files changed, 261 insertions(+), 255 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4265671..548b053 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,15 @@ categories = ["algorithms", "no-std"] edition = "2018" [features] -notable-defaults = [] -bytewise-defaults = [] -slice16-defaults = [] +# use the "NoTable" implementation for the default Crc struct, using no additional memory for a lookup table. +# Takes predence over "bytewise-memory-restrictions" and "slice16-memory-restrictions" +no-table-memory-restrictions = [] +# use the "Bytewise" implementation for the default Crc struct, using 256 entries of the respective width for a lookup table. +# Takes predence over "slice16-memory-restrictions" and is used if no feature is selected +bytewise-memory-restrictions = [] +# use the "Slice16" implementation for the default Crc struct, using 256 * 16 entries of the respective width for a lookup table. +# Can be overriden by setting "bytewise-memory-restrictions" and "slice16-memory-restrictions" +slice16-memory-restrictions = [] [dependencies] crc-catalog = "2.1.0" diff --git a/src/crc128.rs b/src/crc128.rs index 104afa4..f63d3f8 100644 --- a/src/crc128.rs +++ b/src/crc128.rs @@ -177,18 +177,18 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 16; #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))]{ const EXPECTED: usize = 0; let _ = EXPECTED; const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -196,9 +196,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 0; @@ -206,9 +206,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -217,9 +217,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -227,9 +227,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -238,9 +238,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -249,9 +249,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -262,7 +262,7 @@ mod test { let _ = BYTES_PER_ENTRY; } - /// Test this opitimized version against the well known implementation to ensure correctness + /// Test this optimized version against the well known implementation to ensure correctness #[test] fn correctness() { let data: &[&str] = &[ diff --git a/src/crc128/default.rs b/src/crc128/default.rs index d4d71dc..9b80994 100644 --- a/src/crc128/default.rs +++ b/src/crc128/default.rs @@ -1,22 +1,22 @@ use crate::crc128::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -#[cfg(feature = "notable-defaults")] +#[cfg(feature = "no-table-memory-restrictions")] impl Implementation for u128 { type Width = u128; type Table = (); } -#[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] +#[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] impl Implementation for u128 { type Width = u128; type Table = [u128; 256]; } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] impl Implementation for u128 { type Width = u128; @@ -24,9 +24,9 @@ impl Implementation for u128 { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] impl Implementation for u128 { type Width = u128; @@ -36,24 +36,24 @@ impl Implementation for u128 { impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] let table = crate::table::crc128_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] let table = crate::table::crc128_table(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(feature = "notable-defaults")] + #[cfg(feature = "no-table-memory-restrictions")] #[allow(clippy::let_unit_value)] let table = (); #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] let table = crate::table::crc128_table(algorithm.width, algorithm.poly, algorithm.refin); @@ -68,28 +68,28 @@ impl Crc { const fn update(&self, crc: u128, bytes: &[u8]) -> u128 { #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(feature = "notable-defaults")] + #[cfg(feature = "no-table-memory-restrictions")] { super::update_nolookup(crc, self.algorithm, bytes) } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) diff --git a/src/crc16.rs b/src/crc16.rs index aa3a5a8..293a744 100644 --- a/src/crc16.rs +++ b/src/crc16.rs @@ -149,18 +149,18 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 2; #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))]{ const EXPECTED: usize = 0; let _ = EXPECTED; const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -168,9 +168,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 0; @@ -178,9 +178,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -189,9 +189,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -199,9 +199,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -210,9 +210,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -221,9 +221,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -234,7 +234,7 @@ mod test { let _ = BYTES_PER_ENTRY; } - /// Test this opitimized version against the well known implementation to ensure correctness + /// Test this optimized version against the well known implementation to ensure correctness #[test] fn correctness() { let data: &[&str] = &[ diff --git a/src/crc16/default.rs b/src/crc16/default.rs index 01fceac..6fe20ac 100644 --- a/src/crc16/default.rs +++ b/src/crc16/default.rs @@ -1,22 +1,22 @@ use crate::crc16::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -#[cfg(feature = "notable-defaults")] +#[cfg(feature = "no-table-memory-restrictions")] impl Implementation for u16 { type Width = u16; type Table = (); } -#[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] +#[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] impl Implementation for u16 { type Width = u16; type Table = [u16; 256]; } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] impl Implementation for u16 { type Width = u16; @@ -24,9 +24,9 @@ impl Implementation for u16 { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] impl Implementation for u16 { type Width = u16; @@ -36,24 +36,24 @@ impl Implementation for u16 { impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] let table = crate::table::crc16_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] let table = crate::table::crc16_table(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(feature = "notable-defaults")] + #[cfg(feature = "no-table-memory-restrictions")] #[allow(clippy::let_unit_value)] let table = (); #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] let table = crate::table::crc16_table(algorithm.width, algorithm.poly, algorithm.refin); @@ -68,28 +68,28 @@ impl Crc { const fn update(&self, crc: u16, bytes: &[u8]) -> u16 { #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(feature = "notable-defaults")] + #[cfg(feature = "no-table-memory-restrictions")] { super::update_nolookup(crc, self.algorithm, bytes) } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) diff --git a/src/crc32.rs b/src/crc32.rs index 4533dbe..c06f606 100644 --- a/src/crc32.rs +++ b/src/crc32.rs @@ -160,18 +160,18 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 4; #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))]{ const EXPECTED: usize = 0; let _ = EXPECTED; const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -179,9 +179,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 0; @@ -189,9 +189,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -200,9 +200,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -210,9 +210,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -221,9 +221,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -232,9 +232,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -245,7 +245,7 @@ mod test { let _ = BYTES_PER_ENTRY; } - /// Test this opitimized version against the well known implementation to ensure correctness + /// Test this optimized version against the well known implementation to ensure correctness #[test] fn correctness() { let data: &[&str] = &[ diff --git a/src/crc32/default.rs b/src/crc32/default.rs index 0c0eed0..21c5b1f 100644 --- a/src/crc32/default.rs +++ b/src/crc32/default.rs @@ -1,22 +1,22 @@ use crate::crc32::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -#[cfg(feature = "notable-defaults")] +#[cfg(feature = "no-table-memory-restrictions")] impl Implementation for u32 { type Width = u32; type Table = (); } -#[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] +#[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] impl Implementation for u32 { type Width = u32; type Table = [u32; 256]; } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] impl Implementation for u32 { type Width = u32; @@ -24,9 +24,9 @@ impl Implementation for u32 { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] impl Implementation for u32 { type Width = u32; @@ -36,24 +36,24 @@ impl Implementation for u32 { impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] let table = crate::table::crc32_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] let table = crate::table::crc32_table(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(feature = "notable-defaults")] + #[cfg(feature = "no-table-memory-restrictions")] #[allow(clippy::let_unit_value)] let table = (); #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] let table = crate::table::crc32_table(algorithm.width, algorithm.poly, algorithm.refin); @@ -68,28 +68,28 @@ impl Crc { const fn update(&self, crc: u32, bytes: &[u8]) -> u32 { #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(feature = "notable-defaults")] + #[cfg(feature = "no-table-memory-restrictions")] { super::update_nolookup(crc, self.algorithm, bytes) } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) diff --git a/src/crc64.rs b/src/crc64.rs index 8248c57..fcfb0fe 100644 --- a/src/crc64.rs +++ b/src/crc64.rs @@ -162,18 +162,18 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 8; #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))]{ const EXPECTED: usize = 0; let _ = EXPECTED; const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -181,9 +181,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 0; @@ -191,9 +191,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -202,9 +202,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -212,9 +212,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -223,9 +223,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -234,9 +234,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -247,7 +247,7 @@ mod test { let _ = BYTES_PER_ENTRY; } - /// Test this opitimized version against the well known implementation to ensure correctness + /// Test this optimized version against the well known implementation to ensure correctness #[test] fn correctness() { let data: &[&str] = &[ diff --git a/src/crc64/default.rs b/src/crc64/default.rs index 6f3263e..880ab4f 100644 --- a/src/crc64/default.rs +++ b/src/crc64/default.rs @@ -1,22 +1,22 @@ use crate::crc64::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -#[cfg(feature = "notable-defaults")] +#[cfg(feature = "no-table-memory-restrictions")] impl Implementation for u64 { type Width = u64; type Table = (); } -#[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] +#[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] impl Implementation for u64 { type Width = u64; type Table = [u64; 256]; } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] impl Implementation for u64 { type Width = u64; @@ -24,9 +24,9 @@ impl Implementation for u64 { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] impl Implementation for u64 { type Width = u64; @@ -36,24 +36,24 @@ impl Implementation for u64 { impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] let table = crate::table::crc64_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] let table = crate::table::crc64_table(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(feature = "notable-defaults")] + #[cfg(feature = "no-table-memory-restrictions")] #[allow(clippy::let_unit_value)] let table = (); #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] let table = crate::table::crc64_table(algorithm.width, algorithm.poly, algorithm.refin); @@ -68,28 +68,28 @@ impl Crc { const fn update(&self, crc: u64, bytes: &[u8]) -> u64 { #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(feature = "notable-defaults")] + #[cfg(feature = "no-table-memory-restrictions")] { super::update_nolookup(crc, self.algorithm, bytes) } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) diff --git a/src/crc8.rs b/src/crc8.rs index 7b7ba5d..8b8075b 100644 --- a/src/crc8.rs +++ b/src/crc8.rs @@ -96,18 +96,18 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 1; #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - feature = "slice16-defaults" + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))]{ const EXPECTED: usize = 0; let _ = EXPECTED; const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -115,9 +115,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 0; @@ -125,9 +125,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "notable-defaults", - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -136,9 +136,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -146,9 +146,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "notable-defaults"), - feature = "bytewise-defaults", - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -157,9 +157,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -168,9 +168,9 @@ mod test { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -181,7 +181,7 @@ mod test { let _ = BYTES_PER_ENTRY; } - /// Test this opitimized version against the well known implementation to ensure correctness + /// Test this optimized version against the well known implementation to ensure correctness #[test] fn correctness() { let data: &[&str] = &[ diff --git a/src/crc8/default.rs b/src/crc8/default.rs index 7e43e31..1043cad 100644 --- a/src/crc8/default.rs +++ b/src/crc8/default.rs @@ -1,22 +1,22 @@ use crate::crc8::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -#[cfg(feature = "notable-defaults")] +#[cfg(feature = "no-table-memory-restrictions")] impl Implementation for u8 { type Width = u8; type Table = (); } -#[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] +#[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] impl Implementation for u8 { type Width = u8; type Table = [u8; 256]; } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] impl Implementation for u8 { type Width = u8; @@ -24,9 +24,9 @@ impl Implementation for u8 { } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] impl Implementation for u8 { type Width = u8; @@ -36,24 +36,24 @@ impl Implementation for u8 { impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] let table = crate::table::crc8_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] let table = crate::table::crc8_table(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(feature = "notable-defaults")] + #[cfg(feature = "no-table-memory-restrictions")] #[allow(clippy::let_unit_value)] let table = (); #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] let table = crate::table::crc8_table(algorithm.width, algorithm.poly, algorithm.refin); @@ -68,28 +68,28 @@ impl Crc { const fn update(&self, crc: u8, bytes: &[u8]) -> u8 { #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - feature = "slice16-defaults" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { super::update_slice16(crc, &self.table, bytes) } - #[cfg(all(not(feature = "notable-defaults"), feature = "bytewise-defaults"))] + #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] { super::update_bytewise(crc, &self.table, bytes) } - #[cfg(feature = "notable-defaults")] + #[cfg(feature = "no-table-memory-restrictions")] { super::update_nolookup(crc, self.algorithm, bytes) } #[cfg(all( - not(feature = "notable-defaults"), - not(feature = "bytewise-defaults"), - not(feature = "slice16-defaults") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { super::update_bytewise(crc, &self.table, bytes) diff --git a/tests/test_under_all_feature_combinations.sh b/tests/test_under_all_feature_combinations.sh index b476f2c..2bc5244 100755 --- a/tests/test_under_all_feature_combinations.sh +++ b/tests/test_under_all_feature_combinations.sh @@ -3,13 +3,13 @@ set -ex cargo test cargo test --no-default-features -cargo test --features slice16-defaults -cargo test --features bytewise-defaults -cargo test --features notable-defaults +cargo test --features slice16-memory-restrictions +cargo test --features bytewise-memory-restrictions +cargo test --features no-table-memory-restrictions -cargo test --features bytewise-defaults,slice16-defaults -cargo test --features notable-defaults,bytewise-defaults -cargo test --features notable-defaults,slice16-defaults +cargo test --features bytewise-memory-restrictions,slice16-memory-restrictions +cargo test --features no-table-memory-restrictions,bytewise-memory-restrictions +cargo test --features no-table-memory-restrictions,slice16-memory-restrictions -cargo test --features notable-defaults,bytewise-defaults,slice16-defaults +cargo test --features no-table-memory-restrictions,bytewise-memory-restrictions,slice16-memory-restrictions From 692ff85d64cbee472eaa5f41c63dc5cd7527536c Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Mon, 17 Apr 2023 13:32:13 +0200 Subject: [PATCH 11/13] cargo fmt --- src/crc128.rs | 51 ++++++++++++++++++++++--------------------- src/crc128/default.rs | 15 ++++++++++--- src/crc16.rs | 51 ++++++++++++++++++++++--------------------- src/crc16/default.rs | 15 ++++++++++--- src/crc32.rs | 51 ++++++++++++++++++++++--------------------- src/crc32/default.rs | 15 ++++++++++--- src/crc64.rs | 51 ++++++++++++++++++++++--------------------- src/crc64/default.rs | 15 ++++++++++--- src/crc8.rs | 51 ++++++++++++++++++++++--------------------- src/crc8/default.rs | 15 ++++++++++--- 10 files changed, 190 insertions(+), 140 deletions(-) diff --git a/src/crc128.rs b/src/crc128.rs index f63d3f8..f42b0f8 100644 --- a/src/crc128.rs +++ b/src/crc128.rs @@ -177,18 +177,19 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 16; #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" - ))]{ + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" + ))] + { const EXPECTED: usize = 0; let _ = EXPECTED; const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -196,9 +197,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 0; @@ -206,9 +207,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -217,9 +218,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -227,9 +228,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -238,9 +239,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -249,9 +250,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; diff --git a/src/crc128/default.rs b/src/crc128/default.rs index 9b80994..72ae451 100644 --- a/src/crc128/default.rs +++ b/src/crc128/default.rs @@ -7,7 +7,10 @@ impl Implementation for u128 { type Table = (); } -#[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] +#[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" +))] impl Implementation for u128 { type Width = u128; type Table = [u128; 256]; @@ -43,7 +46,10 @@ impl Crc { let table = crate::table::crc128_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] + #[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" + ))] let table = crate::table::crc128_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "no-table-memory-restrictions")] @@ -76,7 +82,10 @@ impl Crc { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] + #[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" + ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } diff --git a/src/crc16.rs b/src/crc16.rs index 293a744..be66eb4 100644 --- a/src/crc16.rs +++ b/src/crc16.rs @@ -149,18 +149,19 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 2; #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" - ))]{ + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" + ))] + { const EXPECTED: usize = 0; let _ = EXPECTED; const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -168,9 +169,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 0; @@ -178,9 +179,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -189,9 +190,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -199,9 +200,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -210,9 +211,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -221,9 +222,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; diff --git a/src/crc16/default.rs b/src/crc16/default.rs index 6fe20ac..dd06e16 100644 --- a/src/crc16/default.rs +++ b/src/crc16/default.rs @@ -7,7 +7,10 @@ impl Implementation for u16 { type Table = (); } -#[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] +#[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" +))] impl Implementation for u16 { type Width = u16; type Table = [u16; 256]; @@ -43,7 +46,10 @@ impl Crc { let table = crate::table::crc16_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] + #[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" + ))] let table = crate::table::crc16_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "no-table-memory-restrictions")] @@ -76,7 +82,10 @@ impl Crc { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] + #[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" + ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } diff --git a/src/crc32.rs b/src/crc32.rs index c06f606..6326f62 100644 --- a/src/crc32.rs +++ b/src/crc32.rs @@ -160,18 +160,19 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 4; #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" - ))]{ + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" + ))] + { const EXPECTED: usize = 0; let _ = EXPECTED; const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -179,9 +180,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 0; @@ -189,9 +190,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -200,9 +201,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -210,9 +211,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -221,9 +222,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -232,9 +233,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; diff --git a/src/crc32/default.rs b/src/crc32/default.rs index 21c5b1f..0f937b9 100644 --- a/src/crc32/default.rs +++ b/src/crc32/default.rs @@ -7,7 +7,10 @@ impl Implementation for u32 { type Table = (); } -#[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] +#[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" +))] impl Implementation for u32 { type Width = u32; type Table = [u32; 256]; @@ -43,7 +46,10 @@ impl Crc { let table = crate::table::crc32_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] + #[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" + ))] let table = crate::table::crc32_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "no-table-memory-restrictions")] @@ -76,7 +82,10 @@ impl Crc { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] + #[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" + ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } diff --git a/src/crc64.rs b/src/crc64.rs index fcfb0fe..699930d 100644 --- a/src/crc64.rs +++ b/src/crc64.rs @@ -162,18 +162,19 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 8; #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" - ))]{ + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" + ))] + { const EXPECTED: usize = 0; let _ = EXPECTED; const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -181,9 +182,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 0; @@ -191,9 +192,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -202,9 +203,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -212,9 +213,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -223,9 +224,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -234,9 +235,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; diff --git a/src/crc64/default.rs b/src/crc64/default.rs index 880ab4f..a559b69 100644 --- a/src/crc64/default.rs +++ b/src/crc64/default.rs @@ -7,7 +7,10 @@ impl Implementation for u64 { type Table = (); } -#[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] +#[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" +))] impl Implementation for u64 { type Width = u64; type Table = [u64; 256]; @@ -43,7 +46,10 @@ impl Crc { let table = crate::table::crc64_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] + #[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" + ))] let table = crate::table::crc64_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "no-table-memory-restrictions")] @@ -76,7 +82,10 @@ impl Crc { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] + #[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" + ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } diff --git a/src/crc8.rs b/src/crc8.rs index 8b8075b..11f664c 100644 --- a/src/crc8.rs +++ b/src/crc8.rs @@ -96,18 +96,19 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 1; #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" - ))]{ + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" + ))] + { const EXPECTED: usize = 0; let _ = EXPECTED; const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + feature = "no-table-memory-restrictions", + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -115,9 +116,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 0; @@ -125,9 +126,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + feature = "no-table-memory-restrictions", + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 0; @@ -136,9 +137,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -146,9 +147,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions", + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -157,9 +158,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + feature = "slice16-memory-restrictions" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -168,9 +169,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-memory-restrictions"), + not(feature = "bytewise-memory-restrictions"), + not(feature = "slice16-memory-restrictions") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; diff --git a/src/crc8/default.rs b/src/crc8/default.rs index 1043cad..b13ff50 100644 --- a/src/crc8/default.rs +++ b/src/crc8/default.rs @@ -7,7 +7,10 @@ impl Implementation for u8 { type Table = (); } -#[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] +#[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" +))] impl Implementation for u8 { type Width = u8; type Table = [u8; 256]; @@ -43,7 +46,10 @@ impl Crc { let table = crate::table::crc8_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] + #[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" + ))] let table = crate::table::crc8_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "no-table-memory-restrictions")] @@ -76,7 +82,10 @@ impl Crc { super::update_slice16(crc, &self.table, bytes) } - #[cfg(all(not(feature = "no-table-memory-restrictions"), feature = "bytewise-memory-restrictions"))] + #[cfg(all( + not(feature = "no-table-memory-restrictions"), + feature = "bytewise-memory-restrictions" + ))] { super::update_bytewise(crc, &self.table, bytes) } From e6a2916c8945ccf635ba43caaba4a645982fa16b Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Sun, 23 Apr 2023 19:03:56 +0200 Subject: [PATCH 12/13] rename features to xxx-mem-limit --- Cargo.toml | 12 ++--- src/crc128.rs | 48 ++++++++--------- src/crc128/default.rs | 54 ++++++++++---------- src/crc16.rs | 48 ++++++++--------- src/crc16/default.rs | 54 ++++++++++---------- src/crc32.rs | 48 ++++++++--------- src/crc32/default.rs | 54 ++++++++++---------- src/crc64.rs | 48 ++++++++--------- src/crc64/default.rs | 54 ++++++++++---------- src/crc8.rs | 48 ++++++++--------- src/crc8/default.rs | 54 ++++++++++---------- tests/test_under_all_feature_combinations.sh | 14 ++--- 12 files changed, 268 insertions(+), 268 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 548b053..a0e8e86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,14 +16,14 @@ edition = "2018" [features] # use the "NoTable" implementation for the default Crc struct, using no additional memory for a lookup table. -# Takes predence over "bytewise-memory-restrictions" and "slice16-memory-restrictions" -no-table-memory-restrictions = [] +# Takes predence over "bytewise-mem-limit" and "slice16-mem-limit" +no-table-mem-limit = [] # use the "Bytewise" implementation for the default Crc struct, using 256 entries of the respective width for a lookup table. -# Takes predence over "slice16-memory-restrictions" and is used if no feature is selected -bytewise-memory-restrictions = [] +# Takes predence over "slice16-mem-limit" and is used if no feature is selected +bytewise-mem-limit = [] # use the "Slice16" implementation for the default Crc struct, using 256 * 16 entries of the respective width for a lookup table. -# Can be overriden by setting "bytewise-memory-restrictions" and "slice16-memory-restrictions" -slice16-memory-restrictions = [] +# Can be overriden by setting "bytewise-mem-limit" and "slice16-mem-limit" +slice16-mem-limit = [] [dependencies] crc-catalog = "2.1.0" diff --git a/src/crc128.rs b/src/crc128.rs index f42b0f8..a380a0e 100644 --- a/src/crc128.rs +++ b/src/crc128.rs @@ -177,9 +177,9 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 16; #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + feature = "no-table-mem-limit", + feature = "bytewise-mem-limit", + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 0; @@ -187,9 +187,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + feature = "no-table-mem-limit", + feature = "bytewise-mem-limit", + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 0; @@ -197,9 +197,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + feature = "no-table-mem-limit", + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 0; @@ -207,9 +207,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + feature = "no-table-mem-limit", + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 0; @@ -218,9 +218,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit", + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -228,9 +228,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit", + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -239,9 +239,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -250,9 +250,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; diff --git a/src/crc128/default.rs b/src/crc128/default.rs index 72ae451..ac4ea3d 100644 --- a/src/crc128/default.rs +++ b/src/crc128/default.rs @@ -1,15 +1,15 @@ use crate::crc128::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -#[cfg(feature = "no-table-memory-restrictions")] +#[cfg(feature = "no-table-mem-limit")] impl Implementation for u128 { type Width = u128; type Table = (); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] impl Implementation for u128 { type Width = u128; @@ -17,9 +17,9 @@ impl Implementation for u128 { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] impl Implementation for u128 { type Width = u128; @@ -27,9 +27,9 @@ impl Implementation for u128 { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] impl Implementation for u128 { type Width = u128; @@ -39,27 +39,27 @@ impl Implementation for u128 { impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] let table = crate::table::crc128_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] let table = crate::table::crc128_table(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(feature = "no-table-memory-restrictions")] + #[cfg(feature = "no-table-mem-limit")] #[allow(clippy::let_unit_value)] let table = (); #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] let table = crate::table::crc128_table(algorithm.width, algorithm.poly, algorithm.refin); @@ -74,31 +74,31 @@ impl Crc { const fn update(&self, crc: u128, bytes: &[u8]) -> u128 { #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(feature = "no-table-memory-restrictions")] + #[cfg(feature = "no-table-mem-limit")] { super::update_nolookup(crc, self.algorithm, bytes) } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) diff --git a/src/crc16.rs b/src/crc16.rs index be66eb4..9001f2f 100644 --- a/src/crc16.rs +++ b/src/crc16.rs @@ -149,9 +149,9 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 2; #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + feature = "no-table-mem-limit", + feature = "bytewise-mem-limit", + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 0; @@ -159,9 +159,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + feature = "no-table-mem-limit", + feature = "bytewise-mem-limit", + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 0; @@ -169,9 +169,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + feature = "no-table-mem-limit", + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 0; @@ -179,9 +179,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + feature = "no-table-mem-limit", + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 0; @@ -190,9 +190,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit", + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -200,9 +200,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit", + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -211,9 +211,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -222,9 +222,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; diff --git a/src/crc16/default.rs b/src/crc16/default.rs index dd06e16..0736c1b 100644 --- a/src/crc16/default.rs +++ b/src/crc16/default.rs @@ -1,15 +1,15 @@ use crate::crc16::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -#[cfg(feature = "no-table-memory-restrictions")] +#[cfg(feature = "no-table-mem-limit")] impl Implementation for u16 { type Width = u16; type Table = (); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] impl Implementation for u16 { type Width = u16; @@ -17,9 +17,9 @@ impl Implementation for u16 { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] impl Implementation for u16 { type Width = u16; @@ -27,9 +27,9 @@ impl Implementation for u16 { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] impl Implementation for u16 { type Width = u16; @@ -39,27 +39,27 @@ impl Implementation for u16 { impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] let table = crate::table::crc16_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] let table = crate::table::crc16_table(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(feature = "no-table-memory-restrictions")] + #[cfg(feature = "no-table-mem-limit")] #[allow(clippy::let_unit_value)] let table = (); #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] let table = crate::table::crc16_table(algorithm.width, algorithm.poly, algorithm.refin); @@ -74,31 +74,31 @@ impl Crc { const fn update(&self, crc: u16, bytes: &[u8]) -> u16 { #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(feature = "no-table-memory-restrictions")] + #[cfg(feature = "no-table-mem-limit")] { super::update_nolookup(crc, self.algorithm, bytes) } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) diff --git a/src/crc32.rs b/src/crc32.rs index 6326f62..0467533 100644 --- a/src/crc32.rs +++ b/src/crc32.rs @@ -160,9 +160,9 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 4; #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + feature = "no-table-mem-limit", + feature = "bytewise-mem-limit", + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 0; @@ -170,9 +170,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + feature = "no-table-mem-limit", + feature = "bytewise-mem-limit", + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 0; @@ -180,9 +180,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + feature = "no-table-mem-limit", + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 0; @@ -190,9 +190,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + feature = "no-table-mem-limit", + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 0; @@ -201,9 +201,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit", + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -211,9 +211,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit", + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -222,9 +222,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -233,9 +233,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; diff --git a/src/crc32/default.rs b/src/crc32/default.rs index 0f937b9..a30e42e 100644 --- a/src/crc32/default.rs +++ b/src/crc32/default.rs @@ -1,15 +1,15 @@ use crate::crc32::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -#[cfg(feature = "no-table-memory-restrictions")] +#[cfg(feature = "no-table-mem-limit")] impl Implementation for u32 { type Width = u32; type Table = (); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] impl Implementation for u32 { type Width = u32; @@ -17,9 +17,9 @@ impl Implementation for u32 { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] impl Implementation for u32 { type Width = u32; @@ -27,9 +27,9 @@ impl Implementation for u32 { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] impl Implementation for u32 { type Width = u32; @@ -39,27 +39,27 @@ impl Implementation for u32 { impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] let table = crate::table::crc32_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] let table = crate::table::crc32_table(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(feature = "no-table-memory-restrictions")] + #[cfg(feature = "no-table-mem-limit")] #[allow(clippy::let_unit_value)] let table = (); #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] let table = crate::table::crc32_table(algorithm.width, algorithm.poly, algorithm.refin); @@ -74,31 +74,31 @@ impl Crc { const fn update(&self, crc: u32, bytes: &[u8]) -> u32 { #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(feature = "no-table-memory-restrictions")] + #[cfg(feature = "no-table-mem-limit")] { super::update_nolookup(crc, self.algorithm, bytes) } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) diff --git a/src/crc64.rs b/src/crc64.rs index 699930d..9abafd2 100644 --- a/src/crc64.rs +++ b/src/crc64.rs @@ -162,9 +162,9 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 8; #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + feature = "no-table-mem-limit", + feature = "bytewise-mem-limit", + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 0; @@ -172,9 +172,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + feature = "no-table-mem-limit", + feature = "bytewise-mem-limit", + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 0; @@ -182,9 +182,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + feature = "no-table-mem-limit", + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 0; @@ -192,9 +192,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + feature = "no-table-mem-limit", + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 0; @@ -203,9 +203,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit", + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -213,9 +213,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit", + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -224,9 +224,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -235,9 +235,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; diff --git a/src/crc64/default.rs b/src/crc64/default.rs index a559b69..0bb5cdc 100644 --- a/src/crc64/default.rs +++ b/src/crc64/default.rs @@ -1,15 +1,15 @@ use crate::crc64::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -#[cfg(feature = "no-table-memory-restrictions")] +#[cfg(feature = "no-table-mem-limit")] impl Implementation for u64 { type Width = u64; type Table = (); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] impl Implementation for u64 { type Width = u64; @@ -17,9 +17,9 @@ impl Implementation for u64 { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] impl Implementation for u64 { type Width = u64; @@ -27,9 +27,9 @@ impl Implementation for u64 { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] impl Implementation for u64 { type Width = u64; @@ -39,27 +39,27 @@ impl Implementation for u64 { impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] let table = crate::table::crc64_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] let table = crate::table::crc64_table(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(feature = "no-table-memory-restrictions")] + #[cfg(feature = "no-table-mem-limit")] #[allow(clippy::let_unit_value)] let table = (); #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] let table = crate::table::crc64_table(algorithm.width, algorithm.poly, algorithm.refin); @@ -74,31 +74,31 @@ impl Crc { const fn update(&self, crc: u64, bytes: &[u8]) -> u64 { #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(feature = "no-table-memory-restrictions")] + #[cfg(feature = "no-table-mem-limit")] { super::update_nolookup(crc, self.algorithm, bytes) } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) diff --git a/src/crc8.rs b/src/crc8.rs index 11f664c..d33d906 100644 --- a/src/crc8.rs +++ b/src/crc8.rs @@ -96,9 +96,9 @@ mod test { const TABLE_SIZE: usize = core::mem::size_of::<::Table>(); const BYTES_PER_ENTRY: usize = 1; #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + feature = "no-table-mem-limit", + feature = "bytewise-mem-limit", + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 0; @@ -106,9 +106,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + feature = "no-table-mem-limit", + feature = "bytewise-mem-limit", + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 0; @@ -116,9 +116,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + feature = "no-table-mem-limit", + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 0; @@ -126,9 +126,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - feature = "no-table-memory-restrictions", - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + feature = "no-table-mem-limit", + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 0; @@ -137,9 +137,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit", + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -147,9 +147,9 @@ mod test { const _: () = assert!(EXPECTED == TABLE_SIZE); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions", - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit", + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; @@ -158,9 +158,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { const EXPECTED: usize = 256 * 16 * BYTES_PER_ENTRY; @@ -169,9 +169,9 @@ mod test { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { const EXPECTED: usize = 256 * BYTES_PER_ENTRY; diff --git a/src/crc8/default.rs b/src/crc8/default.rs index b13ff50..8568259 100644 --- a/src/crc8/default.rs +++ b/src/crc8/default.rs @@ -1,15 +1,15 @@ use crate::crc8::{finalize, init}; use crate::{Algorithm, Crc, Digest, Implementation}; -#[cfg(feature = "no-table-memory-restrictions")] +#[cfg(feature = "no-table-mem-limit")] impl Implementation for u8 { type Width = u8; type Table = (); } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] impl Implementation for u8 { type Width = u8; @@ -17,9 +17,9 @@ impl Implementation for u8 { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] impl Implementation for u8 { type Width = u8; @@ -27,9 +27,9 @@ impl Implementation for u8 { } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] impl Implementation for u8 { type Width = u8; @@ -39,27 +39,27 @@ impl Implementation for u8 { impl Crc { pub const fn new(algorithm: &'static Algorithm) -> Self { #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] let table = crate::table::crc8_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] let table = crate::table::crc8_table(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(feature = "no-table-memory-restrictions")] + #[cfg(feature = "no-table-mem-limit")] #[allow(clippy::let_unit_value)] let table = (); #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] let table = crate::table::crc8_table(algorithm.width, algorithm.poly, algorithm.refin); @@ -74,31 +74,31 @@ impl Crc { const fn update(&self, crc: u8, bytes: &[u8]) -> u8 { #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - feature = "slice16-memory-restrictions" + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + feature = "slice16-mem-limit" ))] { super::update_slice16(crc, &self.table, bytes) } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - feature = "bytewise-memory-restrictions" + not(feature = "no-table-mem-limit"), + feature = "bytewise-mem-limit" ))] { super::update_bytewise(crc, &self.table, bytes) } - #[cfg(feature = "no-table-memory-restrictions")] + #[cfg(feature = "no-table-mem-limit")] { super::update_nolookup(crc, self.algorithm, bytes) } #[cfg(all( - not(feature = "no-table-memory-restrictions"), - not(feature = "bytewise-memory-restrictions"), - not(feature = "slice16-memory-restrictions") + not(feature = "no-table-mem-limit"), + not(feature = "bytewise-mem-limit"), + not(feature = "slice16-mem-limit") ))] { super::update_bytewise(crc, &self.table, bytes) diff --git a/tests/test_under_all_feature_combinations.sh b/tests/test_under_all_feature_combinations.sh index 2bc5244..2b44c73 100755 --- a/tests/test_under_all_feature_combinations.sh +++ b/tests/test_under_all_feature_combinations.sh @@ -3,13 +3,13 @@ set -ex cargo test cargo test --no-default-features -cargo test --features slice16-memory-restrictions -cargo test --features bytewise-memory-restrictions -cargo test --features no-table-memory-restrictions +cargo test --features slice16-mem-limit +cargo test --features bytewise-mem-limit +cargo test --features no-table-mem-limit -cargo test --features bytewise-memory-restrictions,slice16-memory-restrictions -cargo test --features no-table-memory-restrictions,bytewise-memory-restrictions -cargo test --features no-table-memory-restrictions,slice16-memory-restrictions +cargo test --features bytewise-mem-limit,slice16-mem-limit +cargo test --features no-table-mem-limit,bytewise-mem-limit +cargo test --features no-table-mem-limit,slice16-mem-limit -cargo test --features no-table-memory-restrictions,bytewise-memory-restrictions,slice16-memory-restrictions +cargo test --features no-table-mem-limit,bytewise-mem-limit,slice16-mem-limit From 68699a3db51fbecc98d5583193b02d45bfa2fe79 Mon Sep 17 00:00:00 2001 From: Moritz Borcherding Date: Sun, 23 Apr 2023 19:06:28 +0200 Subject: [PATCH 13/13] cargo fmt... --- src/crc128/default.rs | 15 +++------------ src/crc16/default.rs | 15 +++------------ src/crc32/default.rs | 15 +++------------ src/crc64/default.rs | 15 +++------------ src/crc8/default.rs | 15 +++------------ 5 files changed, 15 insertions(+), 60 deletions(-) diff --git a/src/crc128/default.rs b/src/crc128/default.rs index ac4ea3d..d623ac4 100644 --- a/src/crc128/default.rs +++ b/src/crc128/default.rs @@ -7,10 +7,7 @@ impl Implementation for u128 { type Table = (); } -#[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" -))] +#[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] impl Implementation for u128 { type Width = u128; type Table = [u128; 256]; @@ -46,10 +43,7 @@ impl Crc { let table = crate::table::crc128_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" - ))] + #[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] let table = crate::table::crc128_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "no-table-mem-limit")] @@ -82,10 +76,7 @@ impl Crc { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" - ))] + #[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } diff --git a/src/crc16/default.rs b/src/crc16/default.rs index 0736c1b..55b72c9 100644 --- a/src/crc16/default.rs +++ b/src/crc16/default.rs @@ -7,10 +7,7 @@ impl Implementation for u16 { type Table = (); } -#[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" -))] +#[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] impl Implementation for u16 { type Width = u16; type Table = [u16; 256]; @@ -46,10 +43,7 @@ impl Crc { let table = crate::table::crc16_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" - ))] + #[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] let table = crate::table::crc16_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "no-table-mem-limit")] @@ -82,10 +76,7 @@ impl Crc { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" - ))] + #[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } diff --git a/src/crc32/default.rs b/src/crc32/default.rs index a30e42e..0aaedd3 100644 --- a/src/crc32/default.rs +++ b/src/crc32/default.rs @@ -7,10 +7,7 @@ impl Implementation for u32 { type Table = (); } -#[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" -))] +#[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] impl Implementation for u32 { type Width = u32; type Table = [u32; 256]; @@ -46,10 +43,7 @@ impl Crc { let table = crate::table::crc32_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" - ))] + #[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] let table = crate::table::crc32_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "no-table-mem-limit")] @@ -82,10 +76,7 @@ impl Crc { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" - ))] + #[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } diff --git a/src/crc64/default.rs b/src/crc64/default.rs index 0bb5cdc..bf41dc8 100644 --- a/src/crc64/default.rs +++ b/src/crc64/default.rs @@ -7,10 +7,7 @@ impl Implementation for u64 { type Table = (); } -#[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" -))] +#[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] impl Implementation for u64 { type Width = u64; type Table = [u64; 256]; @@ -46,10 +43,7 @@ impl Crc { let table = crate::table::crc64_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" - ))] + #[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] let table = crate::table::crc64_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "no-table-mem-limit")] @@ -82,10 +76,7 @@ impl Crc { super::update_slice16(crc, self.algorithm.refin, &self.table, bytes) } - #[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" - ))] + #[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] { super::update_bytewise(crc, self.algorithm.refin, &self.table, bytes) } diff --git a/src/crc8/default.rs b/src/crc8/default.rs index 8568259..9923b3a 100644 --- a/src/crc8/default.rs +++ b/src/crc8/default.rs @@ -7,10 +7,7 @@ impl Implementation for u8 { type Table = (); } -#[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" -))] +#[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] impl Implementation for u8 { type Width = u8; type Table = [u8; 256]; @@ -46,10 +43,7 @@ impl Crc { let table = crate::table::crc8_table_slice_16(algorithm.width, algorithm.poly, algorithm.refin); - #[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" - ))] + #[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] let table = crate::table::crc8_table(algorithm.width, algorithm.poly, algorithm.refin); #[cfg(feature = "no-table-mem-limit")] @@ -82,10 +76,7 @@ impl Crc { super::update_slice16(crc, &self.table, bytes) } - #[cfg(all( - not(feature = "no-table-mem-limit"), - feature = "bytewise-mem-limit" - ))] + #[cfg(all(not(feature = "no-table-mem-limit"), feature = "bytewise-mem-limit"))] { super::update_bytewise(crc, &self.table, bytes) }