pub trait CodeqConfig{
type Hasher: Hasher + Default;
// Provided methods
fn hash(buf: &[u8]) -> u64 { ... }
fn new_writer<W: Write>(inner: W) -> ChecksumWriter<Self, W> ⓘ { ... }
fn new_reader<R: Read>(inner: R) -> ChecksumReader<Self, R> ⓘ { ... }
fn wrap<T>(data: T) -> WithChecksum<Self, T> { ... }
fn segment(offset: u64, size: u64) -> Segment<Self> { ... }
}Expand description
Static Configuration for checksum calculation and verification.
This trait defines how checksums are calculated and verified for data integrity. It allows applications to:
- Choose their preferred checksum algorithm (e.g., CRC32, CRC64)
- Create checksum-enabled readers and writers
- Wrap data with checksums
§Examples
Using the default CRC32 implementation:
use codeq::config::Crc32fast;
let mut writer = Crc32fast::new_writer(Vec::new());
writer.write_all(b"hello").unwrap();Custom implementation:
use codeq::config::CodeqConfig;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct CustomConfig;
impl CodeqConfig for CustomConfig {
type Hasher = std::collections::hash_map::DefaultHasher;
}Note: Data encoded with one configuration cannot be decoded with a different configuration. For example, data encoded with CRC32 cannot be decoded with CRC64, and vice versa.
Standard bounds (Debug, Clone, Default, etc.) required for use as a generic parameter
in types like WithChecksum<C,T> and Segment<C> throughout the codebase.
Required Associated Types§
Provided Methods§
Sourcefn new_writer<W: Write>(inner: W) -> ChecksumWriter<Self, W> ⓘ
fn new_writer<W: Write>(inner: W) -> ChecksumWriter<Self, W> ⓘ
Creates a new checksum writer wrapping the given writer.
Sourcefn new_reader<R: Read>(inner: R) -> ChecksumReader<Self, R> ⓘ
fn new_reader<R: Read>(inner: R) -> ChecksumReader<Self, R> ⓘ
Creates a new checksum reader wrapping the given reader.
Sourcefn wrap<T>(data: T) -> WithChecksum<Self, T>
fn wrap<T>(data: T) -> WithChecksum<Self, T>
Wraps data with checksum protection.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.