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>
impl<T, const LEN: usize, const REVERSE_STR: bool> Array<T, LEN, REVERSE_STR>
Sourcepub fn with_fill(val: T) -> Selfwhere
T: Copy,
pub fn with_fill(val: T) -> Selfwhere
T: Copy,
Constructs array filled with given value.
TODO: Revert commit 7110cee0cf539d8ff4270450183f7060a585bc87 and make
method const once const_fn_trait_bound stabilize
Sourcepub const fn from_array(inner: [T; LEN]) -> Self
pub const fn from_array(inner: [T; LEN]) -> Self
Wraps inner representation into array type.
Sourcepub fn as_slice_mut(&mut self) -> &mut [T]
pub fn as_slice_mut(&mut self) -> &mut [T]
Returns mutable byte slice representation.
Source§impl<const LEN: usize, const REVERSE_STR: bool> Array<u8, LEN, REVERSE_STR>
impl<const LEN: usize, const REVERSE_STR: bool> Array<u8, LEN, REVERSE_STR>
Sourcepub fn from_slice_unsafe(slice: impl AsRef<[u8]>) -> Self
👎Deprecated since 4.9.0: use from_slice_checked instead
pub fn from_slice_unsafe(slice: impl AsRef<[u8]>) -> Self
from_slice_checked insteadConstructs 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.
Sourcepub fn from_slice_checked(slice: impl AsRef<[u8]>) -> Self
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.
Sourcepub fn to_byte_array(&self) -> [u8; LEN]
pub fn to_byte_array(&self) -> [u8; LEN]
Returns a byte array representation stored in the wrapped type.
Source§impl<T, const LEN: usize, const REVERSE_STR: bool> Array<T, LEN, REVERSE_STR>
impl<T, const LEN: usize, const REVERSE_STR: bool> Array<T, LEN, REVERSE_STR>
Sourcepub fn from_slice(slice: impl AsRef<[T]>) -> Option<Self>
👎Deprecated since 4.2.0: use copy_from_slice
pub fn from_slice(slice: impl AsRef<[T]>) -> Option<Self>
Constructs 256-bit array from a provided slice. If the slice length
is not equal to LEN bytes, returns None
Sourcepub fn copy_from_slice(slice: impl AsRef<[T]>) -> Result<Self, FromSliceError>
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<const LEN: usize, const REVERSE_STR: bool> BitAndAssign for Array<u8, LEN, REVERSE_STR>
impl<const LEN: usize, const REVERSE_STR: bool> BitAndAssign for Array<u8, LEN, REVERSE_STR>
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl<const LEN: usize, const REVERSE_STR: bool> BitOrAssign for Array<u8, LEN, REVERSE_STR>
impl<const LEN: usize, const REVERSE_STR: bool> BitOrAssign for Array<u8, LEN, REVERSE_STR>
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl<const LEN: usize, const REVERSE_STR: bool> BitXorAssign for Array<u8, LEN, REVERSE_STR>
impl<const LEN: usize, const REVERSE_STR: bool> BitXorAssign for Array<u8, LEN, REVERSE_STR>
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read more