From 5dbfa46a3422590fcba320133d5fc4d742cf0086 Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Wed, 5 Oct 2022 12:52:31 -0400 Subject: [PATCH] adds readme; tweak code example --- Cargo.toml | 3 ++- README.md | 17 +++++++++++++++++ src/lib.rs | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/Cargo.toml b/Cargo.toml index de0fb64..e6038ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,13 @@ [package] name = "const-crc32" -version = "1.0.0" +version = "1.0.1" edition = "2021" authors = ["Jonathan Strong "] license = "MIT" description = "A `const fn` implementation of crc32 checksum algorithm" repository = "https://git.shipyard.rs/jstrong/const-crc32" keywords = ["checksum", "crc", "crc32", "const"] +readme = "README.md" [dev-dependencies] crc32fast = "1.2" diff --git a/README.md b/README.md new file mode 100644 index 0000000..cec5f16 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# const-crc32 + +A `const fn` crc32 checksum implementation. + +## Examples + +```rust +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. diff --git a/src/lib.rs b/src/lib.rs index 4a9a992..9ac0678 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,8 @@ //! //! ``` //! const BYTES: &[u8] = "The quick brown fox jumps over the lazy dog".as_bytes(); -//! assert_eq!(const_crc32::crc32(BYTES), 0x414fa339_u32); +//! const CKSUM: u32 = const_crc32::crc32(BYTES); +//! assert_eq!(CKSUM, 0x414fa339_u32); //! ``` /// typically crc32 implementations set up a [u32; 256] lookup table. this computes