Skip to main content

System

Struct System 

Source
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.

InputComputation methodVerification method
&mut StringprotectN/A
&strcomputeverify
char iteratorcompute_from_charsverify_from_chars
u32 iteratorcompute_from_valuesverify_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>>,

Source

pub fn protect(&self, s: &mut String) -> Result<(), ComputeError<char>>

Available on crate feature 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.

Source

pub fn protect_lax(&self, s: &mut String)

Available on crate feature 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.

Source

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.

Source

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.

Source

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.

Source

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>
where Acc: Accumulator + Default, Dec: Decoder<Decoded: IntoIterator<Item = u32>>,

Source

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")?);
Source

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"));
Source

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)?);
Source

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,

Source

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]);
Source

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]);
Source

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)?);
Source

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));
Source

pub const fn with_charset(encoder: Enc, decoder: Dec) -> Self

Creates an instance with Encoder and Decoder.

Trait Implementations§

Source§

impl<const N_CC: usize, Acc: Debug, Enc: Debug, Dec: Debug> Debug for System<N_CC, Acc, Enc, Dec>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N_CC: usize, Acc: Default, Enc: Default, Dec: Default> Default for System<N_CC, Acc, Enc, Dec>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const N_CC: usize, Acc, Enc, Dec> Freeze for System<N_CC, Acc, Enc, Dec>
where PhantomData<Acc>: Freeze, Enc: Freeze, Dec: Freeze,

§

impl<const N_CC: usize, Acc, Enc, Dec> RefUnwindSafe for System<N_CC, Acc, Enc, Dec>

§

impl<const N_CC: usize, Acc, Enc, Dec> Send for System<N_CC, Acc, Enc, Dec>
where PhantomData<Acc>: Send, Enc: Send, Dec: Send,

§

impl<const N_CC: usize, Acc, Enc, Dec> Sync for System<N_CC, Acc, Enc, Dec>
where PhantomData<Acc>: Sync, Enc: Sync, Dec: Sync,

§

impl<const N_CC: usize, Acc, Enc, Dec> Unpin for System<N_CC, Acc, Enc, Dec>
where PhantomData<Acc>: Unpin, Enc: Unpin, Dec: Unpin,

§

impl<const N_CC: usize, Acc, Enc, Dec> UnsafeUnpin for System<N_CC, Acc, Enc, Dec>

§

impl<const N_CC: usize, Acc, Enc, Dec> UnwindSafe for System<N_CC, Acc, Enc, Dec>
where PhantomData<Acc>: UnwindSafe, Enc: UnwindSafe, Dec: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.