pub trait Checksum {
const LEN: usize;
// Required method
fn compute(&self, data: &[u8]) -> u64;
}Expand description
An integrity check over a byte slice that yields Checksum::LEN bytes.
§Example
A one-byte XOR checksum (weak, but a short example):
use wire_codec::checksum::Checksum;
struct Xor8;
impl Checksum for Xor8 {
const LEN: usize = 1;
fn compute(&self, data: &[u8]) -> u64 {
u64::from(data.iter().fold(0u8, |acc, b| acc ^ b))
}
}
assert_eq!(Xor8.compute(&[0x0F, 0xF0]), 0xFF);Required Associated Constants§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".