Type Alias ic_agent::hash_tree::Sha256Digest
source · pub type Sha256Digest = [u8; 32];Expand description
Sha256 Digest: 32 bytes
Implementations§
source§impl<const N: usize> [u8; N]
impl<const N: usize> [u8; N]
sourcepub const fn as_ascii(&self) -> Option<&[AsciiChar; N]>
🔬This is a nightly-only experimental API. (ascii_char)
pub const fn as_ascii(&self) -> Option<&[AsciiChar; N]>
ascii_char)Converts this array of bytes into a array of ASCII characters,
or returns None if any of the characters is non-ASCII.
Examples
#![feature(ascii_char)]
#![feature(const_option)]
const HEX_DIGITS: [std::ascii::Char; 16] =
*b"0123456789abcdef".as_ascii().unwrap();
assert_eq!(HEX_DIGITS[1].as_str(), "1");
assert_eq!(HEX_DIGITS[10].as_str(), "a");sourcepub const unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
🔬This is a nightly-only experimental API. (ascii_char)
pub const unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
ascii_char)Converts this array of bytes into a array of ASCII characters, without checking whether they’re valid.
Safety
Every byte in the array must be in 0..=127, or else this is UB.
source§impl<T, const N: usize> [T; N]
impl<T, const N: usize> [T; N]
1.55.0 · sourcepub fn map<F, U>(self, f: F) -> [U; N]where
F: FnMut(T) -> U,
pub fn map<F, U>(self, f: F) -> [U; N]where F: FnMut(T) -> U,
Returns an array of the same size as self, with function f applied to each element
in order.
If you don’t necessarily need a new fixed-size array, consider using
Iterator::map instead.
Note on performance and stack usage
Unfortunately, usages of this method are currently not always optimized as well as they could be. This mainly concerns large arrays, as mapping over small arrays seem to be optimized just fine. Also note that in debug mode (i.e. without any optimizations), this method can use a lot of stack space (a few times the size of the array or more).
Therefore, in performance-critical code, try to avoid using this method
on large arrays or check the emitted code. Also try to avoid chained
maps (e.g. arr.map(...).map(...)).
In many cases, you can instead use Iterator::map by calling .iter()
or .into_iter() on your array. [T; N]::map is only necessary if you
really need a new array of the same size as the result. Rust’s lazy
iterators tend to get optimized very well.
Examples
let x = [1, 2, 3];
let y = x.map(|v| v + 1);
assert_eq!(y, [2, 3, 4]);
let x = [1, 2, 3];
let mut temp = 0;
let y = x.map(|v| { temp += 1; v * temp });
assert_eq!(y, [1, 4, 9]);
let x = ["Ferris", "Bueller's", "Day", "Off"];
let y = x.map(|v| v.len());
assert_eq!(y, [6, 9, 3, 3]);sourcepub fn try_map<F, R>(
self,
f: F
) -> <<R as Try>::Residual as Residual<[<R as Try>::Output; N]>>::TryTypewhere
F: FnMut(T) -> R,
R: Try,
<R as Try>::Residual: Residual<[<R as Try>::Output; N]>,
🔬This is a nightly-only experimental API. (array_try_map)
pub fn try_map<F, R>( self, f: F ) -> <<R as Try>::Residual as Residual<[<R as Try>::Output; N]>>::TryTypewhere F: FnMut(T) -> R, R: Try, <R as Try>::Residual: Residual<[<R as Try>::Output; N]>,
array_try_map)A fallible function f applied to each element on array self in order to
return an array the same size as self or the first error encountered.
The return type of this function depends on the return type of the closure.
If you return Result<T, E> from the closure, you’ll get a Result<[T; N], E>.
If you return Option<T> from the closure, you’ll get an Option<[T; N]>.
Examples
#![feature(array_try_map)]
let a = ["1", "2", "3"];
let b = a.try_map(|v| v.parse::<u32>()).unwrap().map(|v| v + 1);
assert_eq!(b, [2, 3, 4]);
let a = ["1", "2a", "3"];
let b = a.try_map(|v| v.parse::<u32>());
assert!(b.is_err());
use std::num::NonZeroU32;
let z = [1, 2, 0, 3, 4];
assert_eq!(z.try_map(NonZeroU32::new), None);
let a = [1, 2, 3];
let b = a.try_map(NonZeroU32::new);
let c = b.map(|x| x.map(NonZeroU32::get));
assert_eq!(c, Some(a));1.57.0 (const: 1.57.0) · sourcepub const fn as_slice(&self) -> &[T]
pub const fn as_slice(&self) -> &[T]
Returns a slice containing the entire array. Equivalent to &s[..].
1.57.0 · sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns a mutable slice containing the entire array. Equivalent to
&mut s[..].
sourcepub fn each_ref(&self) -> [&T; N]
🔬This is a nightly-only experimental API. (array_methods)
pub fn each_ref(&self) -> [&T; N]
array_methods)Borrows each element and returns an array of references with the same
size as self.
Example
#![feature(array_methods)]
let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);This method is particularly useful if combined with other methods, like
map. This way, you can avoid moving the original
array if its elements are not Copy.
#![feature(array_methods)]
let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);
// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);sourcepub fn each_mut(&mut self) -> [&mut T; N]
🔬This is a nightly-only experimental API. (array_methods)
pub fn each_mut(&mut self) -> [&mut T; N]
array_methods)Borrows each element mutably and returns an array of mutable references
with the same size as self.
Example
#![feature(array_methods)]
let mut floats = [3.1, 2.7, -1.0];
let float_refs: [&mut f64; 3] = floats.each_mut();
*float_refs[0] = 0.0;
assert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]);
assert_eq!(floats, [0.0, 2.7, -1.0]);sourcepub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
🔬This is a nightly-only experimental API. (split_array)
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
split_array)Divides one array reference into two at an index.
The first will contain all indices from [0, M) (excluding
the index M itself) and the second will contain all
indices from [M, N) (excluding the index N itself).
Panics
Panics if M > N.
Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.split_array_ref::<0>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<2>();
assert_eq!(left, &[1, 2]);
assert_eq!(right, &[3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<6>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}sourcepub fn split_array_mut<const M: usize>(&mut self) -> (&mut [T; M], &mut [T])
🔬This is a nightly-only experimental API. (split_array)
pub fn split_array_mut<const M: usize>(&mut self) -> (&mut [T; M], &mut [T])
split_array)Divides one mutable array reference into two at an index.
The first will contain all indices from [0, M) (excluding
the index M itself) and the second will contain all
indices from [M, N) (excluding the index N itself).
Panics
Panics if M > N.
Examples
#![feature(split_array)]
let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.split_array_mut::<2>();
assert_eq!(left, &mut [1, 0][..]);
assert_eq!(right, &mut [3, 0, 5, 6]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);sourcepub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
🔬This is a nightly-only experimental API. (split_array)
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
split_array)Divides one array reference into two at an index from the end.
The first will contain all indices from [0, N - M) (excluding
the index N - M itself) and the second will contain all
indices from [N - M, N) (excluding the index N itself).
Panics
Panics if M > N.
Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.rsplit_array_ref::<0>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
{
let (left, right) = v.rsplit_array_ref::<2>();
assert_eq!(left, &[1, 2, 3, 4]);
assert_eq!(right, &[5, 6]);
}
{
let (left, right) = v.rsplit_array_ref::<6>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}sourcepub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M])
🔬This is a nightly-only experimental API. (split_array)
pub fn rsplit_array_mut<const M: usize>(&mut self) -> (&mut [T], &mut [T; M])
split_array)Divides one mutable array reference into two at an index from the end.
The first will contain all indices from [0, N - M) (excluding
the index N - M itself) and the second will contain all
indices from [N - M, N) (excluding the index N itself).
Panics
Panics if M > N.
Examples
#![feature(split_array)]
let mut v = [1, 0, 3, 0, 5, 6];
let (left, right) = v.rsplit_array_mut::<4>();
assert_eq!(left, &mut [1, 0]);
assert_eq!(right, &mut [3, 0, 5, 6][..]);
left[1] = 2;
right[1] = 4;
assert_eq!(v, [1, 2, 3, 4, 5, 6]);Trait Implementations§
§impl<T> Array for [T; 32]where
T: Default,
impl<T> Array for [T; 32]where T: Default,
§fn as_slice_mut(&mut self) -> &mut [T]
fn as_slice_mut(&mut self) -> &mut [T]
source§impl<T> Array for [T; 65536]
impl<T> Array for [T; 65536]
§impl<C, B> BinRead for [B; 32]where
C: Copy + 'static,
B: BinRead<Args = C> + Default,
impl<C, B> BinRead for [B; 32]where C: Copy + 'static, B: BinRead<Args = C> + Default,
§type Args = <B as BinRead>::Args
type Args = <B as BinRead>::Args
§fn read_options<R>(
reader: &mut R,
options: &ReadOptions,
args: <[B; 32] as BinRead>::Args
) -> Result<[B; 32], Error>where
R: Read + Seek,
fn read_options<R>( reader: &mut R, options: &ReadOptions, args: <[B; 32] as BinRead>::Args ) -> Result<[B; 32], Error>where R: Read + Seek,
fn after_parse<R>( &mut self, reader: &mut R, ro: &ReadOptions, args: <B as BinRead>::Args ) -> Result<(), Error>where R: Read + Seek,
§fn read<R>(reader: &mut R) -> Result<Self, Error>where
R: Read + Seek,
fn read<R>(reader: &mut R) -> Result<Self, Error>where R: Read + Seek,
§fn read_args<R>(reader: &mut R, args: Self::Args) -> Result<Self, Error>where
R: Read + Seek,
fn read_args<R>(reader: &mut R, args: Self::Args) -> Result<Self, Error>where R: Read + Seek,
§fn args_default() -> Option<Self::Args>
fn args_default() -> Option<Self::Args>
read shortcut method.
Override this for any type that optionally requries arguments1.4.0 · source§impl<T, const N: usize> BorrowMut<[T]> for [T; N]
impl<T, const N: usize> BorrowMut<[T]> for [T; N]
source§fn borrow_mut(&mut self) -> &mut [T]
fn borrow_mut(&mut self) -> &mut [T]
source§impl<T, const N: usize> CandidType for [T; N]where
T: CandidType,
impl<T, const N: usize> CandidType for [T; N]where T: CandidType,
§impl<'a, T, const N: usize> DecodeValue<'a> for [T; N]where
T: Decode<'a>,
impl<'a, T, const N: usize> DecodeValue<'a> for [T; N]where T: Decode<'a>,
§fn decode_value<R>(reader: &mut R, header: Header) -> Result<[T; N], Error>where
R: Reader<'a>,
fn decode_value<R>(reader: &mut R, header: Header) -> Result<[T; N], Error>where R: Reader<'a>,
Reader].source§impl<'de, T> Deserialize<'de> for [T; 32]where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for [T; 32]where T: Deserialize<'de>,
source§fn deserialize<D>(
deserializer: D
) -> Result<[T; 32], <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<[T; 32], <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
§impl<T, const N: usize> EncodeValue for [T; N]where
T: Encode,
impl<T, const N: usize> EncodeValue for [T; N]where T: Encode,
§impl<T> From<GenericArray<T, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>>> for [T; 32]
Available on relaxed_coherence only.
impl<T> From<GenericArray<T, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>>> for [T; 32]
relaxed_coherence only.source§impl<T, const N: usize> From<Simd<T, N>> for [T; N]where
LaneCount<N>: SupportedLaneCount,
T: SimdElement,
impl<T, const N: usize> From<Simd<T, N>> for [T; N]where LaneCount<N>: SupportedLaneCount, T: SimdElement,
1.0.0 · source§impl<T, const N: usize> Hash for [T; N]where
T: Hash,
impl<T, const N: usize> Hash for [T; N]where T: Hash,
The hash of an array is the same as that of the corresponding slice,
as required by the Borrow implementation.
use std::hash::BuildHasher;
let b = std::collections::hash_map::RandomState::new();
let a: [u8; 3] = [0xa8, 0x3c, 0x09];
let s: &[u8] = &[0xa8, 0x3c, 0x09];
assert_eq!(b.hash_one(a), b.hash_one(s));1.53.0 · source§impl<T, const N: usize> IntoIterator for [T; N]
impl<T, const N: usize> IntoIterator for [T; N]
source§fn into_iter(self) -> <[T; N] as IntoIterator>::IntoIter
fn into_iter(self) -> <[T; N] as IntoIterator>::IntoIter
Creates a consuming iterator, that is, one that moves each value out of
the array (from start to end). The array cannot be used after calling
this unless T implements Copy, so the whole array is copied.
Arrays have special behavior when calling .into_iter() prior to the
2021 edition – see the array Editions section for more information.
1.0.0 · source§impl<T, const N: usize> Ord for [T; N]where
T: Ord,
impl<T, const N: usize> Ord for [T; N]where T: Ord,
Implements comparison of arrays lexicographically.
1.0.0 · source§impl<A, B, const N: usize> PartialEq<&mut [B]> for [A; N]where
A: PartialEq<B>,
impl<A, B, const N: usize> PartialEq<&mut [B]> for [A; N]where A: PartialEq<B>,
1.0.0 · source§impl<T, const N: usize> PartialOrd<[T; N]> for [T; N]where
T: PartialOrd<T>,
impl<T, const N: usize> PartialOrd<[T; N]> for [T; N]where T: PartialOrd<T>,
source§fn le(&self, other: &[T; N]) -> bool
fn le(&self, other: &[T; N]) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<T> Serialize for [T; 32]where
T: Serialize,
impl<T> Serialize for [T; 32]where T: Serialize,
source§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,
1.51.0 · source§impl<T, const N: usize> SlicePattern for [T; N]
impl<T, const N: usize> SlicePattern for [T; N]
1.34.0 · source§impl<T, const N: usize> TryFrom<&[T]> for [T; N]where
T: Copy,
impl<T, const N: usize> TryFrom<&[T]> for [T; N]where T: Copy,
Tries to create an array [T; N] by copying from a slice &[T]. Succeeds if
slice.len() == N.
let bytes: [u8; 3] = [1, 0, 2];
let bytes_head: [u8; 2] = <[u8; 2]>::try_from(&bytes[0..2]).unwrap();
assert_eq!(1, u16::from_le_bytes(bytes_head));
let bytes_tail: [u8; 2] = bytes[1..3].try_into().unwrap();
assert_eq!(512, u16::from_le_bytes(bytes_tail));§type Error = TryFromSliceError
type Error = TryFromSliceError
1.59.0 · source§impl<T, const N: usize> TryFrom<&mut [T]> for [T; N]where
T: Copy,
impl<T, const N: usize> TryFrom<&mut [T]> for [T; N]where T: Copy,
Tries to create an array [T; N] by copying from a mutable slice &mut [T].
Succeeds if slice.len() == N.
let mut bytes: [u8; 3] = [1, 0, 2];
let bytes_head: [u8; 2] = <[u8; 2]>::try_from(&mut bytes[0..2]).unwrap();
assert_eq!(1, u16::from_le_bytes(bytes_head));
let bytes_tail: [u8; 2] = (&mut bytes[1..3]).try_into().unwrap();
assert_eq!(512, u16::from_le_bytes(bytes_tail));§type Error = TryFromSliceError
type Error = TryFromSliceError
1.48.0 · source§impl<T, A, const N: usize> TryFrom<Vec<T, A>> for [T; N]where
A: Allocator,
impl<T, A, const N: usize> TryFrom<Vec<T, A>> for [T; N]where A: Allocator,
source§fn try_from(vec: Vec<T, A>) -> Result<[T; N], Vec<T, A>>
fn try_from(vec: Vec<T, A>) -> Result<[T; N], Vec<T, A>>
Gets the entire contents of the Vec<T> as an array,
if its size exactly matches that of the requested array.
Examples
assert_eq!(vec![1, 2, 3].try_into(), Ok([1, 2, 3]));
assert_eq!(<Vec<i32>>::new().try_into(), Ok([]));If the length doesn’t match, the input comes back in Err:
let r: Result<[i32; 4], _> = (0..10).collect::<Vec<_>>().try_into();
assert_eq!(r, Err(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]));If you’re fine with just getting a prefix of the Vec<T>,
you can call .truncate(N) first.
let mut v = String::from("hello world").into_bytes();
v.sort();
v.truncate(2);
let [a, b]: [_; 2] = v.try_into().unwrap();
assert_eq!(a, b' ');
assert_eq!(b, b'd');§impl<Z, const N: usize> Zeroize for [Z; N]where
Z: Zeroize,
impl<Z, const N: usize> Zeroize for [Z; N]where Z: Zeroize,
Impl [Zeroize] on arrays of types that impl [Zeroize].
impl<T, const N: usize> ConstParamTy for [T; N]where T: ConstParamTy,
impl<T, const N: usize> Copy for [T; N]where T: Copy,
impl<T, const N: usize> Eq for [T; N]where T: Eq,
impl<T, const N: usize> StructuralEq for [T; N]
impl<T, const N: usize> StructuralPartialEq for [T; N]
impl<Z, const N: usize> ZeroizeOnDrop for [Z; N]where Z: ZeroizeOnDrop,
Impl [ZeroizeOnDrop] on arrays of types that impl [ZeroizeOnDrop].