Merge pull request #1 from ZcashFoundation/no-std

add no_std support
This commit is contained in:
natalie 2024-02-16 15:55:28 +00:00 committed by GitHub
commit 3b5b17e7ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -1,12 +1,12 @@
[package] [package]
name = "const-crc32" name = "const-crc32-nostd"
version = "1.3.0" version = "1.3.1"
edition = "2021" edition = "2021"
authors = ["Jonathan Strong <jstrong@shipyard.rs>"] authors = ["Jonathan Strong <jstrong@shipyard.rs>"]
license = "MIT" license = "MIT"
description = "A `const fn` implementation of crc32 checksum algorithm" description = "A `const fn` implementation of crc32 checksum algorithm"
repository = "https://git.shipyard.rs/jstrong/const-crc32" repository = "https://git.shipyard.rs/jstrong/const-crc32"
keywords = ["checksum", "crc", "crc32", "const"] keywords = ["checksum", "crc", "crc32", "const", "no_std"]
readme = "README.md" readme = "README.md"
[dev-dependencies] [dev-dependencies]

View File

@ -3,10 +3,12 @@
//! # Examples //! # Examples
//! //!
//! ``` //! ```
//! use const_crc32_nostd as const_crc32;
//! const BYTES: &[u8] = "The quick brown fox jumps over the lazy dog".as_bytes(); //! const BYTES: &[u8] = "The quick brown fox jumps over the lazy dog".as_bytes();
//! const CKSUM: u32 = const_crc32::crc32(BYTES); //! const CKSUM: u32 = const_crc32::crc32(BYTES);
//! assert_eq!(CKSUM, 0x414fa339_u32); //! assert_eq!(CKSUM, 0x414fa339_u32);
//! ``` //! ```
#![no_std]
/// used to generate up a [u32; 256] lookup table in `crc32`. this computes /// used to generate up a [u32; 256] lookup table in `crc32`. this computes
/// the table on demand for a given "index" `i` /// the table on demand for a given "index" `i`
@ -57,6 +59,8 @@ pub const fn crc32(buf: &[u8]) -> u32 {
/// Calculating the checksum from several parts of a larger input: /// Calculating the checksum from several parts of a larger input:
/// ///
/// ``` /// ```
/// use const_crc32_nostd as const_crc32;
///
/// const BYTES: &[u8] = "The quick brown fox jumps over the lazy dog".as_bytes(); /// const BYTES: &[u8] = "The quick brown fox jumps over the lazy dog".as_bytes();
/// ///
/// let mut cksum = 0u32; /// let mut cksum = 0u32;
@ -72,6 +76,8 @@ pub const fn crc32(buf: &[u8]) -> u32 {
/// on what kind of data the bytes represent: /// on what kind of data the bytes represent:
/// ///
/// ``` /// ```
/// use const_crc32_nostd as const_crc32;
///
/// const THING_ONE_SEED: u32 = 0xbaaaaaad_u32; /// const THING_ONE_SEED: u32 = 0xbaaaaaad_u32;
/// const THING_TWO_SEED: u32 = 0x2bad2bad_u32; /// const THING_TWO_SEED: u32 = 0x2bad2bad_u32;
/// ///