[][src]Macro embedded_crc_macros::crc8_hasher_lookup_table

macro_rules! crc8_hasher_lookup_table {
    ($struct_name:ident, $initial_value:expr, $doc:expr) => { ... };
}

Define public structure implementing the CRC-8 algorithm as a core::hash::Hasher trait implementation using a pre-calculated lookup table.

This implementation is much faster at the cost of some space. A struct name and some documentation for it must be provided.

The lookup table can be generated in the build.rs file with the build_rs_lookup_table_file_generation macro and then included like in the following example.

use core::hash::Hasher;
use embedded_crc_macros::crc8_hasher_lookup_table;

// include!(concat!(env!("OUT_DIR"), "/lookup_table.rs"));
crc8_hasher_lookup_table!(SmbusPec, 0, "SMBus Packet Error Code");

let mut hasher = SmbusPec::new();
hasher.write(&[0xAB, 0xCD]);
let pec = hasher.finish();

println!("PEC: {}", pec);