Array

Struct Array 

Source
pub struct Array<T, const LEN: usize, const REVERSE_STR: bool = false>(/* private fields */);
Expand description

Wrapper type for all fixed arrays implementing many important traits, so types based on it can simply derive their implementations.

Type keeps data in little-endian byte order and displays them in the same order (like bitcoin SHA256 single hash type).

Implementations§

Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Array<T, LEN, REVERSE_STR>

Source

pub fn with_fill(val: T) -> Self
where T: Copy,

Constructs array filled with given value. TODO: Revert commit 7110cee0cf539d8ff4270450183f7060a585bc87 and make method const once const_fn_trait_bound stabilize

Source

pub const fn from_array(inner: [T; LEN]) -> Self

Wraps inner representation into array type.

Source

pub fn as_slice(&self) -> &[T]

Returns byte slice representation.

Source

pub fn as_slice_mut(&mut self) -> &mut [T]

Returns mutable byte slice representation.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the array items.

The iterator yields all items from start to end.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator that allows modifying each value.

The iterator yields all items from start to end.

Source§

impl<const LEN: usize, const REVERSE_STR: bool> Array<u8, LEN, REVERSE_STR>

Source

pub const fn zero() -> Self

Constructs array filled with zero bytes

Source

pub fn from_slice_unsafe(slice: impl AsRef<[u8]>) -> Self

👎Deprecated since 4.9.0: use from_slice_checked instead

Constructs a byte array from the slice. Expects the slice length doesn’t match LEN constant generic.

§Safety

Panics if the slice length doesn’t match LEN constant generic.

Source

pub fn from_slice_checked(slice: impl AsRef<[u8]>) -> Self

Constructs a byte array from the slice. Expects the slice length doesn’t match LEN constant generic.

§Safety

Panics if the slice length doesn’t match LEN constant generic.

Source

pub fn to_byte_array(&self) -> [u8; LEN]

Returns a byte array representation stored in the wrapped type.

Source

pub fn from_byte_array(val: impl Into<[u8; LEN]>) -> Self

Constructs Array type from another type containing raw array.

Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Array<T, LEN, REVERSE_STR>
where T: Default + Copy,

Source

pub fn from_slice(slice: impl AsRef<[T]>) -> Option<Self>

👎Deprecated since 4.2.0: use copy_from_slice

Constructs 256-bit array from a provided slice. If the slice length is not equal to LEN bytes, returns None

Source

pub fn copy_from_slice(slice: impl AsRef<[T]>) -> Result<Self, FromSliceError>

Constructs 256-bit array by copying from a provided slice. Errors if the slice length is not equal to LEN bytes.

Trait Implementations§

Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> AsMut<[T]> for Array<T, LEN, REVERSE_STR>

Source§

fn as_mut(&mut self) -> &mut [T]

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

impl<T, const LEN: usize, const REVERSE_STR: bool> AsRef<[T]> for Array<T, LEN, REVERSE_STR>

Source§

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

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

impl<const LEN: usize, const REVERSE_STR: bool> BitAnd for Array<u8, LEN, REVERSE_STR>

Source§

type Output = Array<u8, LEN, REVERSE_STR>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<const LEN: usize, const REVERSE_STR: bool> BitAndAssign for Array<u8, LEN, REVERSE_STR>

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl<const LEN: usize, const REVERSE_STR: bool> BitOr for Array<u8, LEN, REVERSE_STR>

Source§

type Output = Array<u8, LEN, REVERSE_STR>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<const LEN: usize, const REVERSE_STR: bool> BitOrAssign for Array<u8, LEN, REVERSE_STR>

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl<const LEN: usize, const REVERSE_STR: bool> BitXor for Array<u8, LEN, REVERSE_STR>

Source§

type Output = Array<u8, LEN, REVERSE_STR>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<const LEN: usize, const REVERSE_STR: bool> BitXorAssign for Array<u8, LEN, REVERSE_STR>

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Borrow<[T]> for Array<T, LEN, REVERSE_STR>

Source§

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

Immutably borrows from an owned value. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> BorrowMut<[T]> for Array<T, LEN, REVERSE_STR>

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T: Clone, const LEN: usize, const REVERSE_STR: bool> Clone for Array<T, LEN, REVERSE_STR>

Source§

fn clone(&self) -> Array<T, LEN, REVERSE_STR>

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<T, const LEN: usize, const REVERSE_STR: bool> Default for Array<T, LEN, REVERSE_STR>
where T: Default + Copy,

Source§

fn default() -> Self

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

impl<T, const LEN: usize> Dumb for Array<T, LEN>
where T: Dumb + Copy,

Source§

fn dumb() -> Self

Returns an object initialized with dumb data
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> From<[T; LEN]> for Array<T, LEN, REVERSE_STR>

Source§

fn from(array: [T; LEN]) -> Self

Converts to this type from the input type.
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> From<T> for Array<T, LEN, REVERSE_STR>
where T: Into<[T; LEN]>,

Source§

fn from(array: T) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash, const LEN: usize, const REVERSE_STR: bool> Hash for Array<T, LEN, REVERSE_STR>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Index<Range<usize>> for Array<T, LEN, REVERSE_STR>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: Range<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Index<RangeFrom<usize>> for Array<T, LEN, REVERSE_STR>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeFrom<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Index<RangeFull> for Array<T, LEN, REVERSE_STR>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeFull) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Index<RangeInclusive<usize>> for Array<T, LEN, REVERSE_STR>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Index<RangeTo<usize>> for Array<T, LEN, REVERSE_STR>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeTo<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Index<RangeToInclusive<usize>> for Array<T, LEN, REVERSE_STR>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, index: RangeToInclusive<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Index<usize> for Array<T, LEN, REVERSE_STR>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> IndexMut<Range<usize>> for Array<T, LEN, REVERSE_STR>

Source§

fn index_mut(&mut self, index: Range<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> IndexMut<RangeFrom<usize>> for Array<T, LEN, REVERSE_STR>

Source§

fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> IndexMut<RangeFull> for Array<T, LEN, REVERSE_STR>

Source§

fn index_mut(&mut self, index: RangeFull) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> IndexMut<RangeInclusive<usize>> for Array<T, LEN, REVERSE_STR>

Source§

fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> IndexMut<RangeTo<usize>> for Array<T, LEN, REVERSE_STR>

Source§

fn index_mut(&mut self, index: RangeTo<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> IndexMut<RangeToInclusive<usize>> for Array<T, LEN, REVERSE_STR>

Source§

fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> IndexMut<usize> for Array<T, LEN, REVERSE_STR>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> IntoIterator for Array<T, LEN, REVERSE_STR>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, LEN>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<const LEN: usize, const REVERSE_STR: bool> Not for Array<u8, LEN, REVERSE_STR>

Source§

type Output = Array<u8, LEN, REVERSE_STR>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<T: Ord, const LEN: usize, const REVERSE_STR: bool> Ord for Array<T, LEN, REVERSE_STR>

Source§

fn cmp(&self, other: &Array<T, LEN, REVERSE_STR>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq, const LEN: usize, const REVERSE_STR: bool> PartialEq for Array<T, LEN, REVERSE_STR>

Source§

fn eq(&self, other: &Array<T, LEN, REVERSE_STR>) -> 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<T: PartialOrd, const LEN: usize, const REVERSE_STR: bool> PartialOrd for Array<T, LEN, REVERSE_STR>

Source§

fn partial_cmp(&self, other: &Array<T, LEN, REVERSE_STR>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> TryFrom<&[T]> for Array<T, LEN, REVERSE_STR>
where T: Copy + Default,

Source§

type Error = FromSliceError

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

fn try_from(value: &[T]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Wrapper for Array<T, LEN, REVERSE_STR>

Source§

type Inner = [T; LEN]

Inner type wrapped by the current newtype
Source§

fn from_inner(inner: Self::Inner) -> Self

Instantiates wrapper type with the inner data
Source§

fn as_inner(&self) -> &Self::Inner

Returns reference to the inner representation for the wrapper type
Source§

fn into_inner(self) -> Self::Inner

Unwraps the wrapper returning the inner type
Source§

fn to_inner(&self) -> Self::Inner
where Self::Inner: Clone,

Clones inner data of the wrapped type and return them
Source§

fn copy(&self) -> Self
where Self: Sized, Self::Inner: Copy,

Copies the wrapped type
Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> WrapperMut for Array<T, LEN, REVERSE_STR>

Source§

fn as_inner_mut(&mut self) -> &mut Self::Inner

Returns a mutable reference to the inner representation for the wrapper type
Source§

impl<T: Copy, const LEN: usize, const REVERSE_STR: bool> Copy for Array<T, LEN, REVERSE_STR>

Source§

impl<T: Eq, const LEN: usize, const REVERSE_STR: bool> Eq for Array<T, LEN, REVERSE_STR>

Source§

impl<T, const LEN: usize, const REVERSE_STR: bool> StructuralPartialEq for Array<T, LEN, REVERSE_STR>

Auto Trait Implementations§

§

impl<T, const LEN: usize, const REVERSE_STR: bool> Freeze for Array<T, LEN, REVERSE_STR>
where T: Freeze,

§

impl<T, const LEN: usize, const REVERSE_STR: bool> RefUnwindSafe for Array<T, LEN, REVERSE_STR>
where T: RefUnwindSafe,

§

impl<T, const LEN: usize, const REVERSE_STR: bool> Send for Array<T, LEN, REVERSE_STR>
where T: Send,

§

impl<T, const LEN: usize, const REVERSE_STR: bool> Sync for Array<T, LEN, REVERSE_STR>
where T: Sync,

§

impl<T, const LEN: usize, const REVERSE_STR: bool> Unpin for Array<T, LEN, REVERSE_STR>
where T: Unpin,

§

impl<T, const LEN: usize, const REVERSE_STR: bool> UnwindSafe for Array<T, LEN, REVERSE_STR>
where T: 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.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.