nucleo-l053r8-benches/crates/crc/src/lib.rs

30 lines
805 B
Rust
Executable file

//! # CRC's from scratch, nothing else
//!
//! This crate implements some CRC algorithms from scratch in a `no_std` environment.
//!
//! ## Acknowledgements
//!
//! Many thanks to the [crc-catalogue](https://reveng.sourceforge.io/crc-catalogue/) for providing
//! an overview over the various algorithms with test vectors and examples.
#![cfg_attr(not(test), no_std)]
mod crc_32;
pub const CHECK_DATA: [u8; 9] = *b"123456789";
pub use crc_32::*;
pub trait Crc: Sized {
type Input: ?Sized;
type Checksum: Eq + Default + Copy;
fn new() -> Self;
fn process(&mut self, data: &Self::Input);
fn shift_reg(&mut self) -> &mut Self::Checksum;
fn checksum(data: &Self::Input) -> Self::Checksum {
let mut c = Self::new();
c.process(data);
*c.shift_reg()
}
}