Struct CrcCorrector

Source
pub struct CrcCorrector<const L: usize, W: Width> { /* private fields */ }
Expand description

CRC Corrector

Associated const CrcCorrector::L refers to message length in bits including an appended CRC

Implementations§

Source§

impl<const L: usize> CrcCorrector<L, u16>

Source

pub const fn new(crc: Crc<u16, Table<1>>) -> Self

Construct CRC Corrector, including lookup table, for a given CRC algorithm and message length.

§Panics

This function will panic if

  • The message length is not a multiple of 8. (We expect byte data)
  • The requested table length is too large
  • The CRC algorithm cannot reliably perform single bit correction with the required message length

In the last case the problem is similar to a hash collision. Either choose a longer CRC (64 bit vs 32 bit vs 16 bit) or a different algorithm. Ultimately there is a limit to the message length a CRC can correct errors for.

Source

pub fn correct( &self, data: &mut [u8], crc: u16, ) -> Result<Correction<u16>, Error>

Correct message with a single bit of corruption in either the provided message or the provided CRC. This method mutates the message to correct corruption but will not mutate it if correction fails.

If a correction is applied the CRC is validated again to ensure that the integrity of the data is okay. This isn’t strictly necessary, but guards against any bugs which would incorrectly ‘correct’ data.

§Errors

This method will either return an error if correction could not be applied, or will mutate the data with a single bit correction and return an indication of which bit was the issue.

Source§

impl<const L: usize> CrcCorrector<L, u32>

Source

pub const fn new(crc: Crc<u32, Table<1>>) -> Self

Construct CRC Corrector, including lookup table, for a given CRC algorithm and message length.

§Panics

This function will panic if

  • The message length is not a multiple of 8. (We expect byte data)
  • The requested table length is too large
  • The CRC algorithm cannot reliably perform single bit correction with the required message length

In the last case the problem is similar to a hash collision. Either choose a longer CRC (64 bit vs 32 bit vs 16 bit) or a different algorithm. Ultimately there is a limit to the message length a CRC can correct errors for.

Source

pub fn correct( &self, data: &mut [u8], crc: u32, ) -> Result<Correction<u32>, Error>

Correct message with a single bit of corruption in either the provided message or the provided CRC. This method mutates the message to correct corruption but will not mutate it if correction fails.

If a correction is applied the CRC is validated again to ensure that the integrity of the data is okay. This isn’t strictly necessary, but guards against any bugs which would incorrectly ‘correct’ data.

§Errors

This method will either return an error if correction could not be applied, or will mutate the data with a single bit correction and return an indication of which bit was the issue.

Source§

impl<const L: usize> CrcCorrector<L, u64>

Source

pub const fn new(crc: Crc<u64, Table<1>>) -> Self

Construct CRC Corrector, including lookup table, for a given CRC algorithm and message length.

§Panics

This function will panic if

  • The message length is not a multiple of 8. (We expect byte data)
  • The requested table length is too large
  • The CRC algorithm cannot reliably perform single bit correction with the required message length

In the last case the problem is similar to a hash collision. Either choose a longer CRC (64 bit vs 32 bit vs 16 bit) or a different algorithm. Ultimately there is a limit to the message length a CRC can correct errors for.

Source

pub fn correct( &self, data: &mut [u8], crc: u64, ) -> Result<Correction<u64>, Error>

Correct message with a single bit of corruption in either the provided message or the provided CRC. This method mutates the message to correct corruption but will not mutate it if correction fails.

If a correction is applied the CRC is validated again to ensure that the integrity of the data is okay. This isn’t strictly necessary, but guards against any bugs which would incorrectly ‘correct’ data.

§Errors

This method will either return an error if correction could not be applied, or will mutate the data with a single bit correction and return an indication of which bit was the issue.

Trait Implementations§

Source§

impl<const L: usize, W: Clone + Width> Clone for CrcCorrector<L, W>

Source§

fn clone(&self) -> CrcCorrector<L, W>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<const L: usize, W> Freeze for CrcCorrector<L, W>
where W: Freeze,

§

impl<const L: usize, W> RefUnwindSafe for CrcCorrector<L, W>
where W: RefUnwindSafe,

§

impl<const L: usize, W> Send for CrcCorrector<L, W>
where W: Send + Sync,

§

impl<const L: usize, W> Sync for CrcCorrector<L, W>
where W: Sync,

§

impl<const L: usize, W> Unpin for CrcCorrector<L, W>
where W: Unpin,

§

impl<const L: usize, W> UnwindSafe for CrcCorrector<L, W>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.