|
|
|
@ -8,10 +8,6 @@
|
|
|
|
|
//! assert_eq!(CKSUM, 0x414fa339_u32);
|
|
|
|
|
//! ```
|
|
|
|
|
|
|
|
|
|
#![feature(const_eval_limit)] |
|
|
|
|
|
|
|
|
|
#![const_eval_limit = "1000000000"] |
|
|
|
|
|
|
|
|
|
/// used to generate up a [u32; 256] lookup table in `crc32`. this computes
|
|
|
|
|
/// the table on demand for a given "index" `i`
|
|
|
|
|
const fn table_fn(i: u32) -> u32 { |
|
|
|
@ -49,7 +45,12 @@ const TABLE: [u32; 256] = get_table();
|
|
|
|
|
/// if used on dynamic data at runtime. Usage should generally be restricted to declaring
|
|
|
|
|
/// `const` variables based on `static` or `const` data available at build time.
|
|
|
|
|
pub const fn crc32(buf: &[u8]) -> u32 { |
|
|
|
|
let mut out = !0u32; |
|
|
|
|
crc32_seed(buf, 0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[inline] |
|
|
|
|
pub const fn crc32_seed(buf: &[u8], seed: u32) -> u32 { |
|
|
|
|
let mut out = !seed; |
|
|
|
|
let mut i = 0usize; |
|
|
|
|
while i < buf.len() { |
|
|
|
|
out = (out >> 8) ^ TABLE[((out & 0xff) ^ (buf[i] as u32)) as usize]; |
|
|
|
|