WithChecksum

Struct WithChecksum 

Source
pub struct WithChecksum<C, T>
where C: CodeqConfig,
{ /* private fields */ }
Expand description

A wrapper that appends a checksum to the encoded data.

During encoding, the inner data is first encoded, then a checksum of the encoded data is calculated and appended. During decoding, the inner data is first decoded, then the checksum is verified against the decoded data. If the checksums do not match, an error is returned.

The generic parameter C specifies the checksum configuration to use for protecting the data.

Example:

use codeq::config::Crc32fast;

let wc = WithChecksum::<Crc32fast, u64>::new(5);
let mut b = Vec::new();
let n = wc.encode(&mut b).unwrap();
assert_eq!(n, 16);
assert_eq!(
    vec![
        0, 0, 0, 0, 0, 0, 0, 5, // data
        0, 0, 0, 0, 21, 72, 43, 230, // checksum
    ],
    b
);

Create a new wrapper with either WithChecksum::new or CodeqConfig::wrap, for example:

let wc = Crc32fast::wrap(5);

Implementations§

Source§

impl<C, T> WithChecksum<C, T>
where C: CodeqConfig,

Source

pub fn new(data: T) -> Self

Creates a new wrapper around the given data.

Source

pub fn into_inner(self) -> T

Unwraps and returns the inner data

Trait Implementations§

Source§

impl<C, T: Clone> Clone for WithChecksum<C, T>
where C: CodeqConfig + Clone,

Source§

fn clone(&self) -> WithChecksum<C, T>

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

impl<C, T: Debug> Debug for WithChecksum<C, T>
where C: CodeqConfig + Debug,

Source§

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

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

impl<C, T> Decode for WithChecksum<C, T>
where C: CodeqConfig, T: Decode,

Source§

fn decode<R: Read>(r: R) -> Result<Self, Error>

Source§

impl<C, T> Encode for WithChecksum<C, T>
where C: CodeqConfig, T: Encode,

Source§

fn encode<W: Write>(&self, w: W) -> Result<usize, Error>

Source§

fn encode_to_vec(&self) -> Result<Vec<u8>, Error>
where Self: Sealed,

Encodes the value into a new Vec<u8>. Read more
Source§

impl<C, T> FixedSize for WithChecksum<C, T>
where C: CodeqConfig, T: FixedSize,

Source§

fn encoded_size() -> usize

Returns the size in bytes that this type will occupy when encoded. Read more
Source§

impl<C, T: PartialEq> PartialEq for WithChecksum<C, T>

Source§

fn eq(&self, other: &WithChecksum<C, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<C, T: Eq> Eq for WithChecksum<C, T>
where C: CodeqConfig + Eq,

Source§

impl<C, T> StructuralPartialEq for WithChecksum<C, T>
where C: CodeqConfig,

Auto Trait Implementations§

§

impl<C, T> Freeze for WithChecksum<C, T>
where T: Freeze,

§

impl<C, T> RefUnwindSafe for WithChecksum<C, T>

§

impl<C, T> Send for WithChecksum<C, T>
where T: Send, C: Send,

§

impl<C, T> Sync for WithChecksum<C, T>
where T: Sync, C: Sync,

§

impl<C, T> Unpin for WithChecksum<C, T>
where T: Unpin, C: Unpin,

§

impl<C, T> UnwindSafe for WithChecksum<C, T>
where T: UnwindSafe, C: 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> 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, 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.
Source§

impl<T> Codec for T
where T: Encode + Decode,