pub trait CardFormat: Sized {
const MAGIC: [u8; 4];
const VERSION_MAJOR: u8;
const VERSION_MINOR: u8;
// Required method
fn format_name() -> &'static str;
// Provided methods
fn validate_magic(magic: &[u8; 4]) -> Result<()> { ... }
fn validate_version(major: u8, minor: u8) -> Result<()> { ... }
fn validate_payload(_payload: &[u8]) -> Result<()> { ... }
}Expand description
Trait for defining card formats
Implementors define their magic bytes, version requirements, and validation logic. The datacard library handles generic I/O, checksums, and structure.
§Example
ⓘ
use datacard_rs::{CardFormat, CardError};
pub struct TernsigFormat;
impl CardFormat for TernsigFormat {
const MAGIC: [u8; 4] = *b"TERN";
const VERSION_MAJOR: u8 = 1;
const VERSION_MINOR: u8 = 0;
fn validate_payload(payload: &[u8]) -> Result<(), CardError> {
// Ternsig-specific validation
Ok(())
}
}Required Associated Constants§
Sourceconst VERSION_MAJOR: u8
const VERSION_MAJOR: u8
Major version number
Sourceconst VERSION_MINOR: u8
const VERSION_MINOR: u8
Minimum supported minor version
Required Methods§
Sourcefn format_name() -> &'static str
fn format_name() -> &'static str
Format name for error messages
Provided Methods§
Sourcefn validate_payload(_payload: &[u8]) -> Result<()>
fn validate_payload(_payload: &[u8]) -> Result<()>
Validate payload after reading (optional, default no-op)
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.