#const

no-std const-crc32-nostd

A const fn implementation of crc32 checksum algorithm

1 stable release

1.3.1 Feb 26, 2024

#72 in #const

Download history 169/week @ 2024-07-21 93/week @ 2024-07-28 382/week @ 2024-08-04 521/week @ 2024-08-11 91/week @ 2024-08-18 57/week @ 2024-08-25 58/week @ 2024-09-01 427/week @ 2024-09-08 469/week @ 2024-09-15 728/week @ 2024-09-22 701/week @ 2024-09-29 434/week @ 2024-10-06 355/week @ 2024-10-13 423/week @ 2024-10-20 819/week @ 2024-10-27 790/week @ 2024-11-03

2,390 downloads per month
Used in 11 crates (via frost-core)

MIT license

8KB
100 lines

const-crc32

A const fn crc32 checksum implementation.

Examples

const BYTES: &[u8] = "The quick brown fox jumps over the lazy dog".as_bytes();
const CKSUM: u32 = const_crc32::crc32(BYTES);
assert_eq!(CKSUM, 0x414fa339_u32);

Usage

This is a naive implementation that should be expected to have poor performance 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.

#[const_eval_limit]

You may need to increase the crate-wide const_eval_limit setting to use const_crc32 for larger byte slices.

Increating const_eval_limit requires the nightly-only #![feature(const_eval_limit)].

Previously, this crate set the limit itself, however, as of the 2022-10-30 nightly, the value set in const_crc32 does not increase the limit for crates which use the library.

Compile time for const data around 100k is less than 1s.


lib.rs:

A const fn crc32 checksum implementation.

Examples

use const_crc32_nostd as const_crc32;
const BYTES: &[u8] = "The quick brown fox jumps over the lazy dog".as_bytes();
const CKSUM: u32 = const_crc32::crc32(BYTES);
assert_eq!(CKSUM, 0x414fa339_u32);

No runtime deps