Struct FixedBytes
#[repr(transparent)]pub struct FixedBytes<const N: usize>(pub [u8; N]);Expand description
Newtype wrapper for Solidity ABI encoding/decoding [u8; N] for 1 <= N <= 32 as
fixed-size byte sequences.
Ref: https://docs.soliditylang.org/en/latest/types.html#fixed-size-byte-arrays
Tuple Fields§
§0: [u8; N]Implementations§
§impl<const N: usize> FixedBytes<N>
impl<const N: usize> FixedBytes<N>
pub fn from_ref(value: &[u8; N]) -> &FixedBytes<N>
pub fn from_ref(value: &[u8; N]) -> &FixedBytes<N>
Converts a reference to [u8; N] into a reference to FixedBytes<N> (without
copying).
Methods from Deref<Target = [u8; N]>§
Sourcepub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
🔬This is a nightly-only experimental API. (ascii_char)
pub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
ascii_char)Converts this array of bytes into an array of ASCII characters,
or returns None if any of the characters is non-ASCII.
§Examples
#![feature(ascii_char)]
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 unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
🔬This is a nightly-only experimental API. (ascii_char)
pub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
ascii_char)Converts this array of bytes into an 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.
1.57.0 · Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a slice containing the entire array. Equivalent to &s[..].
1.77.0 · Sourcepub fn each_ref(&self) -> [&T; N]
pub fn each_ref(&self) -> [&T; N]
Borrows each element and returns an array of references with the same
size as self.
§Example
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.
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 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 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]);
}Trait Implementations§
§impl<const N: usize> Clone for FixedBytes<N>
impl<const N: usize> Clone for FixedBytes<N>
§fn clone(&self) -> FixedBytes<N>
fn clone(&self) -> FixedBytes<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<const N: usize> Debug for FixedBytes<N>
impl<const N: usize> Debug for FixedBytes<N>
§impl<const N: usize> Decode for FixedBytes<N>
impl<const N: usize> Decode for FixedBytes<N>
§fn decode<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<FixedBytes<N>, Error>where
__CodecInputEdqy: Input,
fn decode<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<FixedBytes<N>, Error>where
__CodecInputEdqy: Input,
§fn decode_into<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy,
dst_: &mut MaybeUninit<FixedBytes<N>>,
) -> Result<DecodeFinished, Error>where
__CodecInputEdqy: Input,
fn decode_into<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy,
dst_: &mut MaybeUninit<FixedBytes<N>>,
) -> Result<DecodeFinished, Error>where
__CodecInputEdqy: Input,
§fn skip<I>(input: &mut I) -> Result<(), Error>where
I: Input,
fn skip<I>(input: &mut I) -> Result<(), Error>where
I: Input,
§fn encoded_fixed_size() -> Option<usize>
fn encoded_fixed_size() -> Option<usize>
§impl<const N: usize> Deref for FixedBytes<N>
impl<const N: usize> Deref for FixedBytes<N>
§impl<const N: usize> Encode for FixedBytes<N>
impl<const N: usize> Encode for FixedBytes<N>
§fn encode_to<__CodecOutputEdqy>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)where
__CodecOutputEdqy: Output + ?Sized,
fn encode_to<__CodecOutputEdqy>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)where
__CodecOutputEdqy: Output + ?Sized,
§fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback>(
&self,
f: __CodecUsingEncodedCallback,
) -> __CodecOutputReturn
fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback>( &self, f: __CodecUsingEncodedCallback, ) -> __CodecOutputReturn
§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
§impl<const N: usize> From<[u8; N]> for FixedBytes<N>
impl<const N: usize> From<[u8; N]> for FixedBytes<N>
§fn from(value: [u8; N]) -> FixedBytes<N>
fn from(value: [u8; N]) -> FixedBytes<N>
§impl<const N: usize> From<FixedBytes<N>> for [u8; N]
impl<const N: usize> From<FixedBytes<N>> for [u8; N]
§fn from(value: FixedBytes<N>) -> [u8; N]
fn from(value: FixedBytes<N>) -> [u8; N]
§impl From<u8> for FixedBytes<1>
impl From<u8> for FixedBytes<1>
§fn from(value: u8) -> FixedBytes<1>
fn from(value: u8) -> FixedBytes<1>
§impl<const N: usize> PartialEq for FixedBytes<N>
impl<const N: usize> PartialEq for FixedBytes<N>
§impl<const N: usize> SolDecode for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
impl<const N: usize> SolDecode for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
§type SolType = FixedBytes<N>
type SolType = FixedBytes<N>
§fn from_sol_type(
value: <FixedBytes<N> as SolDecode>::SolType,
) -> Result<FixedBytes<N>, Error>
fn from_sol_type( value: <FixedBytes<N> as SolDecode>::SolType, ) -> Result<FixedBytes<N>, Error>
Self from Self::SolType.§impl<'a, const N: usize> SolEncode<'a> for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
impl<'a, const N: usize> SolEncode<'a> for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
§type SolType = &'a FixedBytes<N>
type SolType = &'a FixedBytes<N>
§fn to_sol_type(&'a self) -> <FixedBytes<N> as SolEncode<'a>>::SolType
fn to_sol_type(&'a self) -> <FixedBytes<N> as SolEncode<'a>>::SolType
Self to Self::SolType via either a borrow (if possible), or
a possibly expensive conversion otherwise.§const SOL_NAME: &'static str = <<Self::SolType as SolTypeEncode>::AlloyType as AlloySolType>::SOL_NAME
const SOL_NAME: &'static str = <<Self::SolType as SolTypeEncode>::AlloyType as AlloySolType>::SOL_NAME
§impl<const N: usize> SolTopicEncode for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
impl<const N: usize> SolTopicEncode for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
§fn encode_topic<H>(&self, _: H) -> [u8; 32]
fn encode_topic<H>(&self, _: H) -> [u8; 32]
§fn topic_preimage(&self, buffer: &mut Vec<u8>)
fn topic_preimage(&self, buffer: &mut Vec<u8>)
§fn default_topic_preimage(buffer: &mut Vec<u8>)
fn default_topic_preimage(buffer: &mut Vec<u8>)
Self::topic_preimage equivalent for the default value representation of this
type.§fn topic_preimage_size(&self) -> usize
fn topic_preimage_size(&self) -> usize
Self::topic_preimage encoding of this type.§fn default_topic_preimage_size() -> usize
fn default_topic_preimage_size() -> usize
Self::topic_preimage_size equivalent for the default value representation of
this type.§impl<const N: usize> SolTypeDecode for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
impl<const N: usize> SolTypeDecode for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
§fn detokenize(
token: <<FixedBytes<N> as SolTypeDecode>::AlloyType as SolType>::Token<'_>,
) -> Result<FixedBytes<N>, Error>
fn detokenize( token: <<FixedBytes<N> as SolTypeDecode>::AlloyType as SolType>::Token<'_>, ) -> Result<FixedBytes<N>, Error>
§impl<const N: usize> SolTypeEncode for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
impl<const N: usize> SolTypeEncode for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
§const DEFAULT_VALUE: <FixedBytes<N> as SolTokenType>::DefaultType = {transmute(0x0000000000000001): <ink_primitives::sol::FixedBytes<N> as ink_primitives::sol::types::SolTokenType>::DefaultType}
const DEFAULT_VALUE: <FixedBytes<N> as SolTokenType>::DefaultType = {transmute(0x0000000000000001): <ink_primitives::sol::FixedBytes<N> as ink_primitives::sol::types::SolTokenType>::DefaultType}
§fn tokenize(&self) -> <FixedBytes<N> as SolTokenType>::TokenType<'_>
fn tokenize(&self) -> <FixedBytes<N> as SolTokenType>::TokenType<'_>
Self::AlloyType token.§impl<const N: usize> TypeInfo for FixedBytes<N>
impl<const N: usize> TypeInfo for FixedBytes<N>
impl<const N: usize> Copy for FixedBytes<N>
impl<const N: usize> EncodeLike for FixedBytes<N>
impl<const N: usize> Eq for FixedBytes<N>
impl<const N: usize> StructuralPartialEq for FixedBytes<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for FixedBytes<N>
impl<const N: usize> RefUnwindSafe for FixedBytes<N>
impl<const N: usize> Send for FixedBytes<N>
impl<const N: usize> Sync for FixedBytes<N>
impl<const N: usize> Unpin for FixedBytes<N>
impl<const N: usize> UnwindSafe for FixedBytes<N>
Blanket Implementations§
§impl<T> AbiDecodeWith<Ink> for Twhere
T: Decode,
impl<T> AbiDecodeWith<Ink> for Twhere
T: Decode,
§fn decode_with(buffer: &[u8]) -> Result<T, <T as AbiDecodeWith<Ink>>::Error>
fn decode_with(buffer: &[u8]) -> Result<T, <T as AbiDecodeWith<Ink>>::Error>
§impl<T> AbiDecodeWith<Sol> for Twhere
T: SolDecode,
impl<T> AbiDecodeWith<Sol> for Twhere
T: SolDecode,
§fn decode_with(buffer: &[u8]) -> Result<T, <T as AbiDecodeWith<Sol>>::Error>
fn decode_with(buffer: &[u8]) -> Result<T, <T as AbiDecodeWith<Sol>>::Error>
§impl<T> AbiEncodeWith<Ink> for Twhere
T: Encode,
impl<T> AbiEncodeWith<Ink> for Twhere
T: Encode,
§fn encode_with(&self) -> Vec<u8> ⓘ
fn encode_with(&self) -> Vec<u8> ⓘ
§fn encode_to_slice(&self, buffer: &mut [u8]) -> usize
fn encode_to_slice(&self, buffer: &mut [u8]) -> usize
§fn encode_to_vec(&self, buffer: &mut Vec<u8>)
fn encode_to_vec(&self, buffer: &mut Vec<u8>)
§impl<T> AbiEncodeWith<Sol> for Twhere
T: for<'a> SolEncode<'a>,
impl<T> AbiEncodeWith<Sol> for Twhere
T: for<'a> SolEncode<'a>,
§fn encode_with(&self) -> Vec<u8> ⓘ
fn encode_with(&self) -> Vec<u8> ⓘ
§fn encode_to_slice(&self, buffer: &mut [u8]) -> usize
fn encode_to_slice(&self, buffer: &mut [u8]) -> usize
§fn encode_to_vec(&self, buffer: &mut Vec<u8>)
fn encode_to_vec(&self, buffer: &mut Vec<u8>)
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
§fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DecodeAll for Twhere
T: Decode,
impl<T> DecodeAll for Twhere
T: Decode,
§fn decode_all(input: &mut &[u8]) -> Result<T, Error>
fn decode_all(input: &mut &[u8]) -> Result<T, Error>
Self and consume all of the given input data. Read more§impl<E> DecodeConstructorError<Ink> for Ewhere
E: Decode,
impl<E> DecodeConstructorError<Ink> for Ewhere
E: Decode,
§fn decode_error_output(buffer: &[u8]) -> ConstructorError<E>
fn decode_error_output(buffer: &[u8]) -> ConstructorError<E>
§impl<T> DecodeLimit for Twhere
T: Decode,
impl<T> DecodeLimit for Twhere
T: Decode,
§impl<R> DecodeMessageResult<Sol> for Rwhere
R: SolResultDecode,
impl<R> DecodeMessageResult<Sol> for Rwhere
R: SolResultDecode,
§impl<T, U> DefensiveTruncateInto<U> for Twhere
U: DefensiveTruncateFrom<T>,
impl<T, U> DefensiveTruncateInto<U> for Twhere
U: DefensiveTruncateFrom<T>,
§fn defensive_truncate_into(self) -> U
fn defensive_truncate_into(self) -> U
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Hashable for Twhere
T: Codec,
impl<T> Hashable for Twhere
T: Codec,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
fn into_tuple(self) -> Dest
§impl<T> IsType<T> for T
impl<T> IsType<T> for T
§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
§impl<T> KeyedVec for Twhere
T: Codec,
impl<T> KeyedVec for Twhere
T: Codec,
§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T. Read more§impl<T> SolResultDecode for Twhere
T: SolDecode,
impl<T> SolResultDecode for Twhere
T: SolDecode,
§impl<'a, T> SolResultEncode<'a> for Twhere
T: SolEncode<'a>,
impl<'a, T> SolResultEncode<'a> for Twhere
T: SolEncode<'a>,
§impl<P> Storable for Pwhere
P: Codec,
impl<P> Storable for Pwhere
P: Codec,
§fn encode<T>(&self, dest: &mut T)where
T: Output + ?Sized,
fn encode<T>(&self, dest: &mut T)where
T: Output + ?Sized,
§fn decode<I>(input: &mut I) -> Result<P, Error>where
I: Input,
fn decode<I>(input: &mut I) -> Result<P, Error>where
I: Input,
§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
§impl<P, Key> StorableHint<Key> for Pwhere
P: Packed,
Key: StorageKey,
impl<P, Key> StorableHint<Key> for Pwhere
P: Packed,
Key: StorageKey,
§type PreferredKey = AutoKey
type PreferredKey = AutoKey
§impl<P> StorageKey for Pwhere
P: Packed,
impl<P> StorageKey for Pwhere
P: Packed,
§impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
type Error = <U as TryFromKey<T>>::Error
fn try_into_key(self) -> Result<U, <U as TryFromKey<T>>::Error>
§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T.