Struct alloy_primitives::Function
source · #[repr(transparent)]pub struct Function(pub FixedBytes<24>);
Expand description
An Ethereum ABI function pointer, 24 bytes in length.
An address (20 bytes), followed by a function selector (4 bytes).
Encoded identical to bytes24
.
Tuple Fields§
§0: FixedBytes<24>
Implementations§
source§impl Function
impl Function
sourcepub const fn with_last_byte(x: u8) -> Self
pub const fn with_last_byte(x: u8) -> Self
Creates a new byte array with the last byte set to x
.
sourcepub const fn repeat_byte(byte: u8) -> Self
pub const fn repeat_byte(byte: u8) -> Self
Creates a new byte array where all bytes are set to byte
.
sourcepub fn from_slice(src: &[u8]) -> Self
pub fn from_slice(src: &[u8]) -> Self
sourcepub fn left_padding_from(value: &[u8]) -> Self
pub fn left_padding_from(value: &[u8]) -> Self
sourcepub fn right_padding_from(value: &[u8]) -> Self
pub fn right_padding_from(value: &[u8]) -> Self
sourcepub const fn into_array(self) -> [u8; 24]
pub const fn into_array(self) -> [u8; 24]
Returns the inner bytes array.
source§impl Function
impl Function
sourcepub fn from_word(word: FixedBytes<32>) -> Self
pub fn from_word(word: FixedBytes<32>) -> Self
Creates an Ethereum function from an EVM word’s lower 24 bytes
(word[..24]
).
Note that this is different from Address::from_word
, which uses the
upper 20 bytes.
sourcepub fn into_word(&self) -> FixedBytes<32>
pub fn into_word(&self) -> FixedBytes<32>
Right-pads the function to 32 bytes (EVM word size).
Note that this is different from Address::into_word
, which left-pads
the address.
sourcepub fn from_address_and_selector<A, S>(address: A, selector: S) -> Self
pub fn from_address_and_selector<A, S>(address: A, selector: S) -> Self
Creates an Ethereum function from an address and selector.
sourcepub fn as_address_and_selector(&self) -> (&Address, &Selector)
pub fn as_address_and_selector(&self) -> (&Address, &Selector)
Returns references to the address and selector of the function.
sourcepub fn to_address_and_selector(&self) -> (Address, Selector)
pub fn to_address_and_selector(&self) -> (Address, Selector)
Returns the address and selector of the function.
Methods from Deref<Target = FixedBytes<24>>§
pub const ZERO: Self = _
sourcepub fn as_slice(&self) -> &[u8] ⓘ
pub fn as_slice(&self) -> &[u8] ⓘ
Returns a slice containing the entire array. Equivalent to &s[..]
.
sourcepub 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[..]
.
sourcepub fn covers(&self, other: &Self) -> bool
pub fn covers(&self, other: &Self) -> bool
Returns true
if all bits set in self
are also set in b
.
sourcepub fn const_eq(&self, other: &Self) -> bool
pub fn const_eq(&self, other: &Self) -> bool
Compile-time equality. NOT constant-time equality.
sourcepub fn const_is_zero(&self) -> bool
pub fn const_is_zero(&self) -> bool
Returns true
if no bits are set.
Methods from Deref<Target = [u8; N]>§
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.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[..]
.
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);
1.77.0 · sourcepub fn each_mut(&mut self) -> [&mut T; N]
pub fn each_mut(&mut self) -> [&mut T; N]
Borrows each element mutably and returns an array of mutable references
with the same size as self
.
§Example
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]);
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 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 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 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.
Trait Implementations§
source§impl AsMut<FixedBytes<24>> for Function
impl AsMut<FixedBytes<24>> for Function
source§fn as_mut(&mut self) -> &mut FixedBytes<24>
fn as_mut(&mut self) -> &mut FixedBytes<24>
source§impl AsRef<FixedBytes<24>> for Function
impl AsRef<FixedBytes<24>> for Function
source§fn as_ref(&self) -> &FixedBytes<24>
fn as_ref(&self) -> &FixedBytes<24>
source§impl BitAndAssign for Function
impl BitAndAssign for Function
source§fn bitand_assign(&mut self, rhs: Function)
fn bitand_assign(&mut self, rhs: Function)
&=
operation. Read moresource§impl BitOrAssign for Function
impl BitOrAssign for Function
source§fn bitor_assign(&mut self, rhs: Function)
fn bitor_assign(&mut self, rhs: Function)
|=
operation. Read moresource§impl BitXorAssign for Function
impl BitXorAssign for Function
source§fn bitxor_assign(&mut self, rhs: Function)
fn bitxor_assign(&mut self, rhs: Function)
^=
operation. Read moresource§impl<'de> Deserialize<'de> for Function
impl<'de> Deserialize<'de> for Function
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
source§impl From<FixedBytes<24>> for Function
impl From<FixedBytes<24>> for Function
source§fn from(value: FixedBytes<24>) -> Self
fn from(value: FixedBytes<24>) -> Self
source§impl From<Function> for FixedBytes<24>
impl From<Function> for FixedBytes<24>
source§impl<'__deriveMoreLifetime> IntoIterator for &'__deriveMoreLifetime Functionwhere
&'__deriveMoreLifetime FixedBytes<24>: IntoIterator,
impl<'__deriveMoreLifetime> IntoIterator for &'__deriveMoreLifetime Functionwhere
&'__deriveMoreLifetime FixedBytes<24>: IntoIterator,
§type Item = <&'__deriveMoreLifetime FixedBytes<24> as IntoIterator>::Item
type Item = <&'__deriveMoreLifetime FixedBytes<24> as IntoIterator>::Item
§type IntoIter = <&'__deriveMoreLifetime FixedBytes<24> as IntoIterator>::IntoIter
type IntoIter = <&'__deriveMoreLifetime FixedBytes<24> as IntoIterator>::IntoIter
source§impl<'__deriveMoreLifetime> IntoIterator for &'__deriveMoreLifetime mut Functionwhere
&'__deriveMoreLifetime mut FixedBytes<24>: IntoIterator,
impl<'__deriveMoreLifetime> IntoIterator for &'__deriveMoreLifetime mut Functionwhere
&'__deriveMoreLifetime mut FixedBytes<24>: IntoIterator,
§type Item = <&'__deriveMoreLifetime mut FixedBytes<24> as IntoIterator>::Item
type Item = <&'__deriveMoreLifetime mut FixedBytes<24> as IntoIterator>::Item
§type IntoIter = <&'__deriveMoreLifetime mut FixedBytes<24> as IntoIterator>::IntoIter
type IntoIter = <&'__deriveMoreLifetime mut FixedBytes<24> as IntoIterator>::IntoIter
source§impl IntoIterator for Functionwhere
FixedBytes<24>: IntoIterator,
impl IntoIterator for Functionwhere
FixedBytes<24>: IntoIterator,
§type Item = <FixedBytes<24> as IntoIterator>::Item
type Item = <FixedBytes<24> as IntoIterator>::Item
§type IntoIter = <FixedBytes<24> as IntoIterator>::IntoIter
type IntoIter = <FixedBytes<24> as IntoIterator>::IntoIter
source§impl Ord for Function
impl Ord for Function
source§impl PartialEq<&[u8]> for Function
impl PartialEq<&[u8]> for Function
source§impl PartialEq<&[u8; 24]> for Function
impl PartialEq<&[u8; 24]> for Function
source§impl PartialEq<&Function> for [u8]
impl PartialEq<&Function> for [u8]
source§impl PartialEq<&Function> for [u8; 24]
impl PartialEq<&Function> for [u8; 24]
source§impl PartialEq<[u8]> for &Function
impl PartialEq<[u8]> for &Function
source§impl PartialEq<[u8]> for Function
impl PartialEq<[u8]> for Function
source§impl PartialEq<[u8; 24]> for &Function
impl PartialEq<[u8; 24]> for &Function
source§impl PartialEq<[u8; 24]> for Function
impl PartialEq<[u8; 24]> for Function
source§impl PartialEq<Function> for &[u8]
impl PartialEq<Function> for &[u8]
source§impl PartialEq<Function> for &[u8; 24]
impl PartialEq<Function> for &[u8; 24]
source§impl PartialEq<Function> for [u8]
impl PartialEq<Function> for [u8]
source§impl PartialEq<Function> for [u8; 24]
impl PartialEq<Function> for [u8; 24]
source§impl PartialEq for Function
impl PartialEq for Function
source§impl PartialOrd<&[u8]> for Function
impl PartialOrd<&[u8]> for Function
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<&Function> for [u8]
impl PartialOrd<&Function> for [u8]
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<[u8]> for &Function
impl PartialOrd<[u8]> for &Function
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<[u8]> for Function
impl PartialOrd<[u8]> for Function
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<Function> for &[u8]
impl PartialOrd<Function> for &[u8]
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<Function> for [u8]
impl PartialOrd<Function> for [u8]
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd for Function
impl PartialOrd for Function
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Function
impl Eq for Function
impl MaxEncodedLen<{ $len }> for Function
impl StructuralPartialEq for Function
Auto Trait Implementations§
impl Freeze for Function
impl RefUnwindSafe for Function
impl Send for Function
impl Sync for Function
impl Unpin for Function
impl UnwindSafe for Function
Blanket Implementations§
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
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> ToHex for T
impl<T> ToHex for T
source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
ToHexExt
insteadself
into the result.
Lower case letters are used (e.g. f9b4ca
).source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
ToHexExt
insteadself
into the result.
Upper case letters are used (e.g. F9B4CA
).source§impl<T> ToHexExt for T
impl<T> ToHexExt for T
source§fn encode_hex(&self) -> String
fn encode_hex(&self) -> String
self
into the result.
Lower case letters are used (e.g. f9b4ca
).source§fn encode_hex_upper(&self) -> String
fn encode_hex_upper(&self) -> String
self
into the result.
Upper case letters are used (e.g. F9B4CA
).source§fn encode_hex_with_prefix(&self) -> String
fn encode_hex_with_prefix(&self) -> String
self
into the result with prefix 0x
.
Lower case letters are used (e.g. 0xf9b4ca
).source§fn encode_hex_upper_with_prefix(&self) -> String
fn encode_hex_upper_with_prefix(&self) -> String
self
into the result with prefix 0X
.
Upper case letters are used (e.g. 0xF9B4CA
).