Struct amplify::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 to_vec(&self) -> Vec<T>
where T: Clone,

Returns vector representing internal slice data

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

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>

§

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>

§

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>

§

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 copy 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<const LEN: usize, const REVERSE_STR: bool> Debug for Array<u8, LEN, REVERSE_STR>

source§

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

Formats the value using the given formatter. 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<const LEN: usize, const REVERSE_STR: bool> Display for Array<u8, LEN, REVERSE_STR>

source§

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

Formats the value using the given formatter. 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<const LEN: usize, const REVERSE_STR: bool> FromHex for Array<u8, LEN, REVERSE_STR>

source§

fn from_byte_iter<I>(iter: I) -> Result<Self, Error>

Produce an object from a byte iterator
source§

fn from_hex(s: &str) -> Result<Self, Error>

Produce an object from a hex string
source§

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

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
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>

§

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>

§

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>

§

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>

§

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>

§

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>

§

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>

§

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>

§

type Item = T

The type of the elements being iterated over.
§

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> LowerHex for Array<u8, LEN, REVERSE_STR>

source§

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

Formats the value using the given formatter.
source§

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

§

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 + PartialOrd,

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method 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

This method 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

This method 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

This method 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,

§

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<const LEN: usize, const REVERSE_STR: bool> UpperHex for Array<u8, LEN, REVERSE_STR>

source§

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

Formats the value using the given formatter.
source§

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

§

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§

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> 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> 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> ToHex for T
where T: LowerHex,

source§

fn to_hex(&self) -> String

Outputs the hash in hexadecimal form

source§

impl<T> ToOwned for T
where T: Clone,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.