pub trait HasChecksumField {
// Required methods
fn calculate_checksum(&self) -> Result<u16, OtToolsIoError>;
fn check_checksum(&self) -> Result<bool, OtToolsIoError>;
}Expand description
A type has a checksum field which needs implementations to handle calculation and validation
Required Methods§
Sourcefn calculate_checksum(&self) -> Result<u16, OtToolsIoError>
fn calculate_checksum(&self) -> Result<u16, OtToolsIoError>
Method for calculating the checksum value for types that have a checksum field
use ot_tools_io::{HasChecksumField, OctatrackFileIO, BankFile};
let bank = BankFile::from_data_file(&path).unwrap();
assert_eq!(bank.checksum, bank.calculate_checksum().unwrap())Sourcefn check_checksum(&self) -> Result<bool, OtToolsIoError>
fn check_checksum(&self) -> Result<bool, OtToolsIoError>
Method to verify if checksum is valid in some data type. See this thread.
use ot_tools_io::{HasChecksumField, OctatrackFileIO, BankFile};
// true for valid checksum values
assert!(BankFile::from_data_file(&path).unwrap().check_checksum().unwrap())