Repository: mrhooray/crc-rs (language: rust)

Issue:
cargo workspaces
Just wanted to throw this out there since I hadn't heard of them before. [cargo workspaces](https://doc.rust-lang.org/book/second-edition/ch14-03-cargo-workspaces.html) could probably be used for the sub-crate in this crate. The sub-crate *still needs to be published*, but it seems like that will happen automatically (and maybe use the root crates version?). I haven't looked into it too extensively, but thought you might want to know.


Discussion / hints:

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index ae8ac0e..0fbd686 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,11 +9,9 @@ repository = "https://github.com/mrhooray/crc-rs.git"
 license = "MIT"
 
 [dependencies]
-crc-core = "0.1"
 build_const = { version = "0.2", default-features = false }
 
 [build-dependencies]
-crc-core = "0.1"
 build_const = "0.2"
 
 [features]
diff --git a/build.rs b/build.rs
index a22115b..db4d77a 100644
--- a/build.rs
+++ b/build.rs
@@ -1,6 +1,7 @@
-extern crate crc_core;
 extern crate build_const;
 
+include!("src/util.rs");
+
 #[allow(non_snake_case)]
 fn create_constants() {
     let mut crc32 = build_const::ConstWriter::for_build("crc32_constants")
@@ -8,15 +9,15 @@ fn create_constants() {
         .finish_dependencies();
     let CASTAGNOLI: u32 = 0x82f63b78;
     crc32.add_value("CASTAGNOLI", "u32", CASTAGNOLI);
-    crc32.add_array("CASTAGNOLI_TABLE", "u32", &crc_core::make_table_crc32(CASTAGNOLI));
+    crc32.add_array("CASTAGNOLI_TABLE", "u32", &make_table_crc32(CASTAGNOLI));
 
     let IEEE: u32 = 0xedb88320;
     crc32.add_value("IEEE", "u32", IEEE);
-    crc32.add_array("IEEE_TABLE", "u32", &crc_core::make_table_crc32(IEEE));
+    crc32.add_array("IEEE_TABLE", "u32", &make_table_crc32(IEEE));
 
     let KOOPMAN: u32 = 0xeb31d82e;
     crc32.add_value("KOOPMAN", "u32", KOOPMAN);
-    crc32.add_array("KOOPMAN_TABLE", "u32", &crc_core::make_table_crc32(KOOPMAN));
+    crc32.add_array("KOOPMAN_TABLE", "u32", &make_table_crc32(KOOPMAN));
 
     crc32.finish();
 
@@ -26,11 +27,11 @@ fn create_constants() {
 
     let ECMA: u64 = 0xc96c5795d7870f42;
     crc64.add_value("ECMA", "u64", ECMA);
-    crc64.add_array("ECMA_TABLE", "u64", &crc_core::make_table_crc64(ECMA));
+    crc64.add_array("ECMA_TABLE", "u64", &make_table_crc64(ECMA));
 
     let ISO: u64 = 0xd800000000000000;
     crc64.add_value("ISO", "u64", ISO);
-    crc64.add_array("ISO_TABLE", "u64", &crc_core::make_table_crc64(ISO));
+    crc64.add_array("ISO_TABLE", "u64", &make_table_crc64(ISO));
 
     crc64.finish();
 }
diff --git a/src/crc32.rs b/src/crc32.rs
index c4c3077..a1de5c7 100644
--- a/src/crc32.rs
+++ b/src/crc32.rs
@@ -3,7 +3,7 @@ use std::hash::Hasher;
 #[cfg(not(feature = "std"))]
 use core::hash::Hasher;
 
-pub use crc_core::make_table_crc32 as make_table;
+pub use util::make_table_crc32 as make_table;
 
 build_const!("crc32_constants");
 
diff --git a/src/crc64.rs b/src/crc64.rs
index c2fe4cd..6d9b894 100644
--- a/src/crc64.rs
+++ b/src/crc64.rs
@@ -3,7 +3,7 @@ use std::hash::Hasher;
 #[cfg(not(feature = "std"))]
 use core::hash::Hasher;
 
-pub use crc_core::make_table_crc64 as make_table;
+pub use util::make_table_crc64 as make_table;
 
 build_const!("crc64_constants");
 
diff --git a/src/lib.rs b/src/lib.rs
index 60dacfb..963a675 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -44,10 +44,10 @@
 
 #[macro_use]
 extern crate build_const;
-extern crate crc_core;
 
 pub mod crc32;
 pub mod crc64;
+mod util;
 
 pub use self::crc32::Hasher32;
 pub use self::crc64::Hasher64;
diff --git a/src/util.rs b/src/util.rs
new file mode 100644
index 0000000..384d9fb
--- /dev/null
+++ b/src/util.rs
@@ -0,0 +1,31 @@
+pub fn make_table_crc32(poly: u32) -> [u32; 256] {
+    let mut table = [0u32; 256];
+    for i in 0..256 {
+        let mut value = i as u32;
+        for _ in 0..8 {
+            value = if (value & 1) == 1 {
+                (value >> 1) ^ poly
+            } else {
+                value >> 1
+            }
+        }
+        table[i] = value;
+    }
+    table
+}
+
+pub fn make_table_crc64(poly: u64) -> [u64; 256] {
+    let mut table = [0u64; 256];
+    for i in 0..256 {
+        let mut value = i as u64;
+        for _ in 0..8 {
+            value = if (value & 1) == 1 {
+                (value >> 1) ^ poly
+            } else {
+                value >> 1
+            }
+        }
+        table[i] = value;
+    }
+    table
+}


Test patch: