pub struct System<const N_CC: usize, Acc, Enc, Dec> { /* private fields */ }Expand description
A generic facade structure combining Accumulator and character set into a check character
system interface.
This type provides computation and verification methods for four types of input as follows. Each
method has its _lax variant that ignores any invalid characters in the input, rather than
reporting an error.
| Input | Computation method | Verification method |
|---|---|---|
&mut String | protect | N/A |
&str | compute | verify |
char iterator | compute_from_chars | verify_from_chars |
u32 iterator | compute_from_values | verify_from_values |
Implementations§
Source§impl<const N_CC: usize, Acc, Enc, Dec> System<N_CC, Acc, Enc, Dec>where
Acc: Accumulator<Computed = [u32; N_CC]> + Default,
Enc: Encoder,
Dec: Decoder<Decoded: IntoIterator<Item = u32>>,
impl<const N_CC: usize, Acc, Enc, Dec> System<N_CC, Acc, Enc, Dec>where
Acc: Accumulator<Computed = [u32; N_CC]> + Default,
Enc: Encoder,
Dec: Decoder<Decoded: IntoIterator<Item = u32>>,
Sourcepub fn protect(&self, s: &mut String) -> Result<(), ComputeError<char>>
Available on crate feature alloc only.
pub fn protect(&self, s: &mut String) -> Result<(), ComputeError<char>>
alloc only.Computes the check characters for the string s and appends them.
§Errors
Returns a ComputeError if the input contains any character that is not in the character
set.
§Examples
use iso_7064::MOD11_2;
let mut buf = String::from("327");
MOD11_2.protect(&mut buf)?;
assert_eq!(buf, "327X");§Panics
Panics if the System is configured with an incompatible Encoder and Accumulator
pair such that the encoder cannot encode check character values produced by the accumulator.
Sourcepub fn protect_lax(&self, s: &mut String)
Available on crate feature alloc only.
pub fn protect_lax(&self, s: &mut String)
alloc only.Computes the check characters for the string s and appends them, ignoring any invalid
characters.
§Examples
use iso_7064::MOD11_2;
let mut buf = String::from("3.2.7.");
MOD11_2.protect_lax(&mut buf);
assert_eq!(buf, "3.2.7.X");§Panics
Panics if the System is configured with an incompatible Encoder and Accumulator
pair such that the encoder cannot encode check character values produced by the accumulator.
Sourcepub fn compute(&self, s: &str) -> Result<[char; N_CC], ComputeError<char>>
pub fn compute(&self, s: &str) -> Result<[char; N_CC], ComputeError<char>>
Computes the check characters for the string s.
§Errors
Returns a ComputeError if the input contains any character that is not in the character
set.
§Examples
use iso_7064::MOD37_2;
assert_eq!(MOD37_2.compute("5S7U")?, ['G']);§Panics
Panics if the System is configured with an incompatible Encoder and Accumulator
pair such that the encoder cannot encode check character values produced by the accumulator.
Sourcepub fn compute_lax(&self, s: &str) -> [char; N_CC]
pub fn compute_lax(&self, s: &str) -> [char; N_CC]
Computes the check characters for the string s, ignoring any invalid characters.
§Examples
use iso_7064::MOD37_2;
assert_eq!(MOD37_2.compute_lax("5S=7U"), ['G']);§Panics
Panics if the System is configured with an incompatible Encoder and Accumulator
pair such that the encoder cannot encode check character values produced by the accumulator.
Sourcepub fn compute_from_chars(
&self,
chars: impl IntoIterator<Item = char>,
) -> Result<[char; N_CC], ComputeError<char>>
pub fn compute_from_chars( &self, chars: impl IntoIterator<Item = char>, ) -> Result<[char; N_CC], ComputeError<char>>
Computes the check characters from an iterator of characters.
§Errors
Returns a ComputeError if the input contains any character that is not in the character
set.
§Examples
use iso_7064::MOD11_10;
let iter = ['2', '0', '6', '5', '1'];
assert_eq!(MOD11_10.compute_from_chars(iter)?, ['8']);§Panics
Panics if the System is configured with an incompatible Encoder and Accumulator
pair such that the encoder cannot encode check character values produced by the accumulator.
Sourcepub fn compute_from_chars_lax(
&self,
chars: impl IntoIterator<Item = char>,
) -> [char; N_CC]
pub fn compute_from_chars_lax( &self, chars: impl IntoIterator<Item = char>, ) -> [char; N_CC]
Computes the check characters from an iterator of characters, ignoring any invalid characters.
§Examples
use iso_7064::MOD11_10;
let iter = ['2', '0', '-', '6', '5', '-', '1', '.'];
assert_eq!(MOD11_10.compute_from_chars_lax(iter), ['8']);§Panics
Panics if the System is configured with an incompatible Encoder and Accumulator
pair such that the encoder cannot encode check character values produced by the accumulator.
Source§impl<const N_CC: usize, Acc, Enc, Dec> System<N_CC, Acc, Enc, Dec>
impl<const N_CC: usize, Acc, Enc, Dec> System<N_CC, Acc, Enc, Dec>
Sourcepub fn verify(&self, s: &str) -> Result<bool, VerifyError<char>>
pub fn verify(&self, s: &str) -> Result<bool, VerifyError<char>>
Verifies whether the check characters in the string s are valid.
§Errors
Returns a VerifyError if the input contains any character that is not in the character
set, or if a supplementary check character (e.g., X or *) is found before the end.
§Examples
use iso_7064::MOD661_26;
assert!(MOD661_26.verify("MVEISJV")?);Sourcepub fn verify_lax(&self, s: &str) -> bool
pub fn verify_lax(&self, s: &str) -> bool
Verifies whether the check characters in the string s are valid, ignoring any invalid
characters.
For this purpose, supplementary check characters (e.g., X or *) found before the end are
regarded as invalid and ignored.
§Examples
use iso_7064::MOD661_26;
assert!(MOD661_26.verify_lax("MV-EIS:JV"));Sourcepub fn verify_from_chars(
&self,
chars: impl IntoIterator<Item = char>,
) -> Result<bool, VerifyError<char>>
pub fn verify_from_chars( &self, chars: impl IntoIterator<Item = char>, ) -> Result<bool, VerifyError<char>>
Verifies whether the check characters in the iterator of characters are valid.
§Errors
Returns a VerifyError if the input contains any character that is not in the character
set, or if a supplementary check character (e.g., X or *) is found before the end.
§Examples
use iso_7064::MOD97_10;
let iter = "3793".chars().chain(['6', '8']);
assert!(MOD97_10.verify_from_chars(iter)?);Sourcepub fn verify_from_chars_lax(
&self,
chars: impl IntoIterator<Item = char>,
) -> bool
pub fn verify_from_chars_lax( &self, chars: impl IntoIterator<Item = char>, ) -> bool
Verifies whether the check characters in the iterator of characters are valid, ignoring any invalid characters.
For this purpose, supplementary check characters (e.g., X or *) found before the end are
regarded as invalid and ignored.
§Examples
use iso_7064::MOD97_10;
let iter = "[3793]".chars().chain(['(', '6', '8', ')']);
assert!(MOD97_10.verify_from_chars_lax(iter));Source§impl<const N_CC: usize, Acc, Enc, Dec> System<N_CC, Acc, Enc, Dec>where
Acc: Accumulator + Default,
impl<const N_CC: usize, Acc, Enc, Dec> System<N_CC, Acc, Enc, Dec>where
Acc: Accumulator + Default,
Sourcepub fn compute_from_values(
&self,
values: impl IntoIterator<Item = u32>,
) -> Result<Acc::Computed, ComputeError<u32>>
pub fn compute_from_values( &self, values: impl IntoIterator<Item = u32>, ) -> Result<Acc::Computed, ComputeError<u32>>
Computes the check character values from an iterator of numerical values.
§Errors
Returns a ComputeError if the input contains any value that is not in the character set.
§Examples
use iso_7064::MOD37_36;
let iter = [21, 14, 5, 34];
assert_eq!(MOD37_36.compute_from_values(iter)?, [17]);Sourcepub fn compute_from_values_lax(
&self,
values: impl IntoIterator<Item = u32>,
) -> Acc::Computed
pub fn compute_from_values_lax( &self, values: impl IntoIterator<Item = u32>, ) -> Acc::Computed
Computes the check character values from an iterator of numerical values, ignoring any invalid values.
§Examples
use iso_7064::MOD37_36;
let iter = [21, 99, 14, 999, 5, 9999, 34];
assert_eq!(MOD37_36.compute_from_values_lax(iter), [17]);Sourcepub fn verify_from_values(
&self,
values: impl IntoIterator<Item = u32>,
) -> Result<bool, VerifyError<u32>>
pub fn verify_from_values( &self, values: impl IntoIterator<Item = u32>, ) -> Result<bool, VerifyError<u32>>
Verifies whether the check character values in the iterator of numerical values are valid.
§Errors
Returns a VerifyError if the input contains any value that is not in the character set,
or if a supplementary check character value is found before the end.
§Examples
use iso_7064::MOD27_26;
let iter = [2, 13, 17, 11].into_iter().chain([15]);
assert!(MOD27_26.verify_from_values(iter)?);Sourcepub fn verify_from_values_lax(
&self,
values: impl IntoIterator<Item = u32>,
) -> bool
pub fn verify_from_values_lax( &self, values: impl IntoIterator<Item = u32>, ) -> bool
Verifies whether the check character values in the iterator of numerical values are valid, ignoring any invalid values.
For this purpose, supplementary check character values found before the end are regarded as invalid and ignored.
§Examples
use iso_7064::MOD27_26;
let iter = [2, 13, 28, 17, 11].into_iter().chain([29, 15, 30, 31]);
assert!(MOD27_26.verify_from_values_lax(iter));