hooks_rs::utils

Struct ComparableArray

Source
pub struct ComparableArray<'a, T, const N: usize>
where T: PartialEq,
{ /* private fields */ }
Expand description

Comparable array of variables.

This can be used when manually calling is_buffer_equal to compare two arrays is to be avoided.

Using ComparableArray over is_buffer_equal is generally preferred, since it is more readable.

§Example

const A: &[u8; 14] = b"same same same";
const B: &[u8; 14] = b"same same same";

const COMPARABLE_A: ComparableArray<u8, 14> = ComparableArray::new(A);
const COMPARABLE_B: ComparableArray<u8, 14> = ComparableArray::new(B);

if COMPARABLE_A != COMPARABLE_B {
    rollback(b"arrays are not the same", -1);
}

Implementations§

Source§

impl<'a, T: PartialEq, const N: usize> ComparableArray<'a, T, N>

Source

pub const fn new(data: &'a [T; N]) -> Self

Create a new ComparableArray

Trait Implementations§

Source§

impl<T: PartialEq, const N: usize> AsRef<[T]> for ComparableArray<'_, T, N>

Source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a, T, const N: usize> From<&'a [T; N]> for ComparableArray<'a, T, N>
where T: PartialEq,

Source§

fn from(data: &'a [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<T, const N: usize> PartialEq for ComparableArray<'_, T, N>
where T: PartialEq,

Source§

fn eq(&self, other: &Self) -> 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.

Auto Trait Implementations§

§

impl<'a, T, const N: usize> Freeze for ComparableArray<'a, T, N>

§

impl<'a, T, const N: usize> RefUnwindSafe for ComparableArray<'a, T, N>
where T: RefUnwindSafe,

§

impl<'a, T, const N: usize> Send for ComparableArray<'a, T, N>
where T: Sync,

§

impl<'a, T, const N: usize> Sync for ComparableArray<'a, T, N>
where T: Sync,

§

impl<'a, T, const N: usize> Unpin for ComparableArray<'a, T, N>

§

impl<'a, T, const N: usize> UnwindSafe for ComparableArray<'a, T, N>
where T: RefUnwindSafe,

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