Type Alias Selector
pub type Selector = FixedBytes<4>;
Expand description
Solidity contract functions are addressed using the first four bytes of the Keccak-256 hash of their signature.
Aliased Type§
struct Selector(pub [u8; 4]);
Fields§
§0: [u8; 4]
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 4 bytes
Implementations
§impl<const N: usize> FixedBytes<N>
impl<const N: usize> FixedBytes<N>
pub const ZERO: FixedBytes<N>
pub const ZERO: FixedBytes<N>
Array of Zero bytes.
pub const fn new(bytes: [u8; N]) -> FixedBytes<N>
pub const fn new(bytes: [u8; N]) -> FixedBytes<N>
Wraps the given byte array in FixedBytes
.
pub const fn with_last_byte(x: u8) -> FixedBytes<N>
pub const fn with_last_byte(x: u8) -> FixedBytes<N>
Creates a new FixedBytes
with the last byte set to x
.
pub const fn repeat_byte(byte: u8) -> FixedBytes<N>
pub const fn repeat_byte(byte: u8) -> FixedBytes<N>
Creates a new FixedBytes
where all bytes are set to byte
.
pub fn random() -> FixedBytes<N>
Available on crate feature getrandom
only.
pub fn random() -> FixedBytes<N>
getrandom
only.Creates a new FixedBytes
with the default cryptographic random number generator.
This is rand::thread_rng
if the “rand” and “std” features are enabled, otherwise
it uses getrandom::getrandom
. Both are cryptographically secure.
pub fn try_random() -> Result<FixedBytes<N>, Error>
Available on crate feature getrandom
only.
pub fn try_random() -> Result<FixedBytes<N>, Error>
getrandom
only.Tries to create a new FixedBytes
with the default cryptographic random number
generator.
See random
for more details.
pub fn random_with<R>(rng: &mut R) -> FixedBytes<N>
Available on crate feature rand
only.
pub fn random_with<R>(rng: &mut R) -> FixedBytes<N>
rand
only.Creates a new FixedBytes
with the given random number generator.
See random
for more details.
pub fn randomize(&mut self)
Available on crate feature getrandom
only.
pub fn randomize(&mut self)
getrandom
only.Fills this FixedBytes
with the default cryptographic random number generator.
See random
for more details.
pub fn try_randomize(&mut self) -> Result<(), Error>
Available on crate feature getrandom
only.
pub fn try_randomize(&mut self) -> Result<(), Error>
getrandom
only.Tries to fill this FixedBytes
with the default cryptographic random number
generator.
See random
for more details.
pub fn randomize_with<R>(&mut self, rng: &mut R)
Available on crate feature rand
only.
pub fn randomize_with<R>(&mut self, rng: &mut R)
rand
only.Fills this FixedBytes
with the given random number generator.
pub const fn concat_const<const M: usize, const Z: usize>(
self,
other: FixedBytes<M>,
) -> FixedBytes<Z>
pub const fn concat_const<const M: usize, const Z: usize>( self, other: FixedBytes<M>, ) -> FixedBytes<Z>
Concatenate two FixedBytes
.
Due to constraints in the language, the user must specify the value of
the output size Z
.
§Panics
Panics if Z
is not equal to N + M
.
pub fn from_slice(src: &[u8]) -> FixedBytes<N>
pub fn from_slice(src: &[u8]) -> FixedBytes<N>
Create a new FixedBytes
from the given slice src
.
For a fallible version, use the TryFrom<&[u8]>
implementation.
§Note
The given bytes are interpreted in big endian order.
§Panics
If the length of src
and the number of bytes in Self
do not match.
pub fn left_padding_from(value: &[u8]) -> FixedBytes<N>
pub fn left_padding_from(value: &[u8]) -> FixedBytes<N>
Create a new FixedBytes
from the given slice src
, left-padding it
with zeroes if necessary.
§Note
The given bytes are interpreted in big endian order.
§Panics
Panics if src.len() > N
.
pub fn right_padding_from(value: &[u8]) -> FixedBytes<N>
pub fn right_padding_from(value: &[u8]) -> FixedBytes<N>
Create a new FixedBytes
from the given slice src
, right-padding it
with zeroes if necessary.
§Note
The given bytes are interpreted in big endian order.
§Panics
Panics if src.len() > N
.
pub const fn as_slice(&self) -> &[u8] ⓘ
pub const fn as_slice(&self) -> &[u8] ⓘ
Returns a slice containing the entire array. Equivalent to &s[..]
.
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Returns a mutable slice containing the entire array. Equivalent to
&mut s[..]
.
pub fn covers(&self, other: &FixedBytes<N>) -> bool
pub fn covers(&self, other: &FixedBytes<N>) -> bool
Returns true
if all bits set in self
are also set in b
.
pub const fn const_covers(self, other: FixedBytes<N>) -> bool
pub const fn const_covers(self, other: FixedBytes<N>) -> bool
Returns true
if all bits set in self
are also set in b
.
pub const fn const_eq(&self, other: &FixedBytes<N>) -> bool
pub const fn const_eq(&self, other: &FixedBytes<N>) -> bool
Compile-time equality. NOT constant-time equality.
pub const fn const_is_zero(&self) -> bool
pub const fn const_is_zero(&self) -> bool
Returns true
if no bits are set.
pub const fn bit_and(self, rhs: FixedBytes<N>) -> FixedBytes<N>
pub const fn bit_and(self, rhs: FixedBytes<N>) -> FixedBytes<N>
Computes the bitwise AND of two FixedBytes
.
pub const fn bit_or(self, rhs: FixedBytes<N>) -> FixedBytes<N>
pub const fn bit_or(self, rhs: FixedBytes<N>) -> FixedBytes<N>
Computes the bitwise OR of two FixedBytes
.
pub const fn bit_xor(self, rhs: FixedBytes<N>) -> FixedBytes<N>
pub const fn bit_xor(self, rhs: FixedBytes<N>) -> FixedBytes<N>
Computes the bitwise XOR of two FixedBytes
.
Trait Implementations
§impl<'arbitrary, const N: usize> Arbitrary<'arbitrary> for FixedBytes<N>
impl<'arbitrary, const N: usize> Arbitrary<'arbitrary> for FixedBytes<N>
§fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<FixedBytes<N>, Error>
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<FixedBytes<N>, Error>
Self
from the given unstructured data. Read more§fn arbitrary_take_rest(
u: Unstructured<'arbitrary>,
) -> Result<FixedBytes<N>, Error>
fn arbitrary_take_rest( u: Unstructured<'arbitrary>, ) -> Result<FixedBytes<N>, Error>
Self
from the entirety of the given
unstructured data. Read more§impl<const N: usize> Arbitrary for FixedBytes<N>
impl<const N: usize> Arbitrary for FixedBytes<N>
§type Parameters = <[u8; N] as Arbitrary>::Parameters
type Parameters = <[u8; N] as Arbitrary>::Parameters
arbitrary_with
accepts for configuration
of the generated Strategy
. Parameters must implement Default
.§type Strategy = Map<<[u8; N] as Arbitrary>::Strategy, fn(_: [u8; N]) -> FixedBytes<N>>
type Strategy = Map<<[u8; N] as Arbitrary>::Strategy, fn(_: [u8; N]) -> FixedBytes<N>>
Strategy
used to generate values of type Self
.§fn arbitrary_with(
_top: <FixedBytes<N> as Arbitrary>::Parameters,
) -> <FixedBytes<N> as Arbitrary>::Strategy
fn arbitrary_with( _top: <FixedBytes<N> as Arbitrary>::Parameters, ) -> <FixedBytes<N> as Arbitrary>::Strategy
§impl<const N: usize> AsMut<[u8]> for FixedBytes<N>
impl<const N: usize> AsMut<[u8]> for FixedBytes<N>
§impl<const N: usize> AsRef<[u8]> for FixedBytes<N>
impl<const N: usize> AsRef<[u8]> for FixedBytes<N>
§impl<const N: usize> BitAnd for FixedBytes<N>
impl<const N: usize> BitAnd for FixedBytes<N>
§type Output = FixedBytes<N>
type Output = FixedBytes<N>
&
operator.§fn bitand(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitAnd>::Output
fn bitand(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitAnd>::Output
&
operation. Read more§impl<const N: usize> BitAndAssign for FixedBytes<N>
impl<const N: usize> BitAndAssign for FixedBytes<N>
§fn bitand_assign(&mut self, rhs: FixedBytes<N>)
fn bitand_assign(&mut self, rhs: FixedBytes<N>)
&=
operation. Read more§impl<const N: usize> BitOr for FixedBytes<N>
impl<const N: usize> BitOr for FixedBytes<N>
§type Output = FixedBytes<N>
type Output = FixedBytes<N>
|
operator.§fn bitor(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitOr>::Output
fn bitor(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitOr>::Output
|
operation. Read more§impl<const N: usize> BitOrAssign for FixedBytes<N>
impl<const N: usize> BitOrAssign for FixedBytes<N>
§fn bitor_assign(&mut self, rhs: FixedBytes<N>)
fn bitor_assign(&mut self, rhs: FixedBytes<N>)
|=
operation. Read more§impl<const N: usize> BitXor for FixedBytes<N>
impl<const N: usize> BitXor for FixedBytes<N>
§type Output = FixedBytes<N>
type Output = FixedBytes<N>
^
operator.§fn bitxor(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitXor>::Output
fn bitxor(self, rhs: FixedBytes<N>) -> <FixedBytes<N> as BitXor>::Output
^
operation. Read more§impl<const N: usize> BitXorAssign for FixedBytes<N>
impl<const N: usize> BitXorAssign for FixedBytes<N>
§fn bitxor_assign(&mut self, rhs: FixedBytes<N>)
fn bitxor_assign(&mut self, rhs: FixedBytes<N>)
^=
operation. Read more§impl<const N: usize> Borrow<[u8]> for FixedBytes<N>
impl<const N: usize> Borrow<[u8]> for FixedBytes<N>
§impl<const N: usize> BorrowMut<[u8]> for FixedBytes<N>
impl<const N: usize> BorrowMut<[u8]> for FixedBytes<N>
§fn borrow_mut(&mut self) -> &mut [u8] ⓘ
fn borrow_mut(&mut self) -> &mut [u8] ⓘ
§impl<const N: usize> BorrowMut<[u8; N]> for FixedBytes<N>
impl<const N: usize> BorrowMut<[u8; N]> for FixedBytes<N>
§fn borrow_mut(&mut self) -> &mut [u8; N]
fn borrow_mut(&mut self) -> &mut [u8; N]
§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> Compact for FixedBytes<N>
impl<const N: usize> Compact for FixedBytes<N>
§fn to_compact<B>(&self, buf: &mut B) -> usize
fn to_compact<B>(&self, buf: &mut B) -> usize
§fn from_compact(buf: &[u8], len: usize) -> (FixedBytes<N>, &[u8])
fn from_compact(buf: &[u8], len: usize) -> (FixedBytes<N>, &[u8])
buf
with its internal cursor
advanced (eg..advance(len)
). Read more§fn specialized_to_compact<B>(&self, buf: &mut B) -> usize
fn specialized_to_compact<B>(&self, buf: &mut B) -> usize
§fn specialized_from_compact(buf: &[u8], len: usize) -> (Self, &[u8])
fn specialized_from_compact(buf: &[u8], len: usize) -> (Self, &[u8])
§impl<const N: usize> Debug for FixedBytes<N>
impl<const N: usize> Debug for FixedBytes<N>
§impl<const N: usize> Decodable for FixedBytes<N>
impl<const N: usize> Decodable for FixedBytes<N>
§fn decode(buf: &mut &[u8]) -> Result<FixedBytes<N>, Error>
fn decode(buf: &mut &[u8]) -> Result<FixedBytes<N>, Error>
buf
must be advanced past
the decoded object.§impl<const N: usize> Decode for FixedBytes<N>
impl<const N: usize> Decode for FixedBytes<N>
§fn is_ssz_fixed_len() -> bool
fn is_ssz_fixed_len() -> bool
true
if this object has a fixed-length. Read more§fn ssz_fixed_len() -> usize
fn ssz_fixed_len() -> usize
§fn from_ssz_bytes(bytes: &[u8]) -> Result<FixedBytes<N>, DecodeError>
fn from_ssz_bytes(bytes: &[u8]) -> Result<FixedBytes<N>, DecodeError>
§impl<const N: usize> Default for FixedBytes<N>
impl<const N: usize> Default for FixedBytes<N>
§fn default() -> FixedBytes<N>
fn default() -> FixedBytes<N>
§impl<const N: usize> Deref for FixedBytes<N>
impl<const N: usize> Deref for FixedBytes<N>
§impl<const N: usize> DerefMut for FixedBytes<N>
impl<const N: usize> DerefMut for FixedBytes<N>
§fn deref_mut(&mut self) -> &mut <FixedBytes<N> as Deref>::Target
fn deref_mut(&mut self) -> &mut <FixedBytes<N> as Deref>::Target
§impl<'de, const N: usize> Deserialize<'de> for FixedBytes<N>
impl<'de, const N: usize> Deserialize<'de> for FixedBytes<N>
§fn deserialize<D>(
deserializer: D,
) -> Result<FixedBytes<N>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<FixedBytes<N>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
§impl<const N: usize> Display for FixedBytes<N>
impl<const N: usize> Display for FixedBytes<N>
§impl<const N: usize> Encodable for FixedBytes<N>
impl<const N: usize> Encodable for FixedBytes<N>
§impl<const N: usize> Encode for FixedBytes<N>
impl<const N: usize> Encode for FixedBytes<N>
§fn is_ssz_fixed_len() -> bool
fn is_ssz_fixed_len() -> bool
true
if this object has a fixed-length. Read more§fn ssz_bytes_len(&self) -> usize
fn ssz_bytes_len(&self) -> usize
self
is serialized. Read more§fn ssz_fixed_len() -> usize
fn ssz_fixed_len() -> usize
§fn ssz_append(&self, buf: &mut Vec<u8>)
fn ssz_append(&self, buf: &mut Vec<u8>)
§impl<const N: usize> From<&[u8; N]> for FixedBytes<N>
impl<const N: usize> From<&[u8; N]> for FixedBytes<N>
§fn from(bytes: &[u8; N]) -> FixedBytes<N>
fn from(bytes: &[u8; N]) -> FixedBytes<N>
§impl<const N: usize> From<&mut [u8; N]> for FixedBytes<N>
impl<const N: usize> From<&mut [u8; N]> for FixedBytes<N>
§fn from(bytes: &mut [u8; N]) -> FixedBytes<N>
fn from(bytes: &mut [u8; N]) -> FixedBytes<N>
§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 From<Signed<32, 1>> for FixedBytes<4>
impl From<Signed<32, 1>> for FixedBytes<4>
§fn from(value: Signed<32, 1>) -> FixedBytes<4>
fn from(value: Signed<32, 1>) -> FixedBytes<4>
Converts a fixed-width unsigned integer into a fixed byte array by interpreting the bytes as big-endian.
§impl From<Uint<32, 1>> for FixedBytes<4>
impl From<Uint<32, 1>> for FixedBytes<4>
§fn from(value: Uint<32, 1>) -> FixedBytes<4>
fn from(value: Uint<32, 1>) -> FixedBytes<4>
Converts a fixed-width unsigned integer into a fixed byte array by interpreting the bytes as big-endian.
§impl From<i32> for FixedBytes<4>
impl From<i32> for FixedBytes<4>
§fn from(value: i32) -> FixedBytes<4>
fn from(value: i32) -> FixedBytes<4>
Converts a fixed-width unsigned integer into a fixed byte array by interpreting the bytes as big-endian.
§impl From<u32> for FixedBytes<4>
impl From<u32> for FixedBytes<4>
§fn from(value: u32) -> FixedBytes<4>
fn from(value: u32) -> FixedBytes<4>
Converts a fixed-width unsigned integer into a fixed byte array by interpreting the bytes as big-endian.
§impl<const N: usize> FromHex for FixedBytes<N>
impl<const N: usize> FromHex for FixedBytes<N>
§fn from_hex<T>(
hex: T,
) -> Result<FixedBytes<N>, <FixedBytes<N> as FromHex>::Error>
fn from_hex<T>( hex: T, ) -> Result<FixedBytes<N>, <FixedBytes<N> as FromHex>::Error>
Self
from the given hex string, or fails
with a custom error type. Read more§impl<const N: usize> FromStr for FixedBytes<N>
impl<const N: usize> FromStr for FixedBytes<N>
§impl<const N: usize> Hash for FixedBytes<N>
impl<const N: usize> Hash for FixedBytes<N>
§impl<__IdxT, const N: usize> Index<__IdxT> for FixedBytes<N>
impl<__IdxT, const N: usize> Index<__IdxT> for FixedBytes<N>
§impl<__IdxT, const N: usize> IndexMut<__IdxT> for FixedBytes<N>
impl<__IdxT, const N: usize> IndexMut<__IdxT> for FixedBytes<N>
§impl<const N: usize> IntoIterator for FixedBytes<N>
impl<const N: usize> IntoIterator for FixedBytes<N>
§type IntoIter = <[u8; N] as IntoIterator>::IntoIter
type IntoIter = <[u8; N] as IntoIterator>::IntoIter
§fn into_iter(self) -> <FixedBytes<N> as IntoIterator>::IntoIter
fn into_iter(self) -> <FixedBytes<N> as IntoIterator>::IntoIter
§impl<const N: usize> LowerHex for FixedBytes<N>
impl<const N: usize> LowerHex for FixedBytes<N>
§impl<const N: usize> Not for FixedBytes<N>
impl<const N: usize> Not for FixedBytes<N>
§type Output = FixedBytes<N>
type Output = FixedBytes<N>
!
operator.§impl<const N: usize> Ord for FixedBytes<N>
impl<const N: usize> Ord for FixedBytes<N>
§impl<const N: usize> PartialEq<&[u8]> for FixedBytes<N>
impl<const N: usize> PartialEq<&[u8]> for FixedBytes<N>
§impl<const N: usize> PartialEq<[u8]> for FixedBytes<N>
impl<const N: usize> PartialEq<[u8]> for FixedBytes<N>
§impl<const N: usize> PartialEq for FixedBytes<N>
impl<const N: usize> PartialEq for FixedBytes<N>
§impl<const N: usize> PartialOrd<&[u8]> for FixedBytes<N>
impl<const N: usize> PartialOrd<&[u8]> for FixedBytes<N>
§impl<const N: usize> PartialOrd<[u8]> for FixedBytes<N>
impl<const N: usize> PartialOrd<[u8]> for FixedBytes<N>
§impl<const N: usize> PartialOrd for FixedBytes<N>
impl<const N: usize> PartialOrd for FixedBytes<N>
§impl<const N: usize> Serialize for FixedBytes<N>
impl<const N: usize> Serialize for FixedBytes<N>
§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,
§impl<const N: usize> SolValue for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
impl<const N: usize> SolValue for FixedBytes<N>where
ByteCount<N>: SupportedFixedBytes,
§fn sol_type_name(&self) -> Cow<'static, str>
fn sol_type_name(&self) -> Cow<'static, str>
sol_name
instead§fn tokenize(&self) -> <Self::SolType as SolType>::Token<'_>
fn tokenize(&self) -> <Self::SolType as SolType>::Token<'_>
§fn detokenize(token: <Self::SolType as SolType>::Token<'_>) -> Selfwhere
Self: From<<Self::SolType as SolType>::RustType>,
fn detokenize(token: <Self::SolType as SolType>::Token<'_>) -> Selfwhere
Self: From<<Self::SolType as SolType>::RustType>,
§fn abi_encoded_size(&self) -> usize
fn abi_encoded_size(&self) -> usize
§fn eip712_data_word(&self) -> FixedBytes<32>
fn eip712_data_word(&self) -> FixedBytes<32>
encodeData
rules, and hash it
if necessary. Read more§fn abi_encode_packed_to(&self, out: &mut Vec<u8>)
fn abi_encode_packed_to(&self, out: &mut Vec<u8>)
§fn abi_encode_sequence(&self) -> Vec<u8> ⓘwhere
<Self::SolType as SolType>::Token<'a>: for<'a> TokenSeq<'a>,
fn abi_encode_sequence(&self) -> Vec<u8> ⓘwhere
<Self::SolType as SolType>::Token<'a>: for<'a> TokenSeq<'a>,
§fn abi_encode_params(&self) -> Vec<u8> ⓘwhere
<Self::SolType as SolType>::Token<'a>: for<'a> TokenSeq<'a>,
fn abi_encode_params(&self) -> Vec<u8> ⓘwhere
<Self::SolType as SolType>::Token<'a>: for<'a> TokenSeq<'a>,
§fn abi_decode(data: &[u8], validate: bool) -> Result<Self, Error>where
Self: From<<Self::SolType as SolType>::RustType>,
fn abi_decode(data: &[u8], validate: bool) -> Result<Self, Error>where
Self: From<<Self::SolType as SolType>::RustType>,
§impl<const N: usize> TryFrom<&[u8]> for FixedBytes<N>
Tries to create a FixedBytes<N>
by copying from a slice &[u8]
. Succeeds
if slice.len() == N
.
impl<const N: usize> TryFrom<&[u8]> for FixedBytes<N>
Tries to create a FixedBytes<N>
by copying from a slice &[u8]
. Succeeds
if slice.len() == N
.
§type Error = TryFromSliceError
type Error = TryFromSliceError
§fn try_from(
slice: &[u8],
) -> Result<FixedBytes<N>, <FixedBytes<N> as TryFrom<&[u8]>>::Error>
fn try_from( slice: &[u8], ) -> Result<FixedBytes<N>, <FixedBytes<N> as TryFrom<&[u8]>>::Error>
§impl<const N: usize> TryFrom<&mut [u8]> for FixedBytes<N>
Tries to create a FixedBytes<N>
by copying from a mutable slice &mut [u8]
. Succeeds if slice.len() == N
.
impl<const N: usize> TryFrom<&mut [u8]> for FixedBytes<N>
Tries to create a FixedBytes<N>
by copying from a mutable slice &mut [u8]
. Succeeds if slice.len() == N
.