Struct ink_lang_ir::Selector
source · [−]pub struct Selector { /* private fields */ }
Expand description
The selector of an ink! dispatchable.
Note
This is equal to the first four bytes of the SHA-3 hash of a function’s name.
Implementations
sourceimpl Selector
impl Selector
sourcepub fn compute(input: &[u8]) -> Self
pub fn compute(input: &[u8]) -> Self
Computes the BLAKE-2 256-bit based selector from the given input bytes.
sourcepub fn compose<'a, T>(trait_prefix: T, fn_ident: &Ident) -> Self where
T: Into<Option<TraitPrefix<'a>>>,
pub fn compose<'a, T>(trait_prefix: T, fn_ident: &Ident) -> Self where
T: Into<Option<TraitPrefix<'a>>>,
Note
trait_prefix
isNone
when computing the selector of ink! constructors and messages in inherent implementation blocks.trait_prefix
isSome
when computing the selector of ink! constructors and messages in trait implementation blocks. In this case thenamespace
is either the full path of the trait definition gained by Rust’smodule_path!
macro by default or it is customized by manual application of the#[ink(namespace = "my_namespace")]
ink! attribute. In the examplemy_namespace
concatenated with::
and the identifier of the trait definition would then be part of the providedtrait_prefix
parameter.fn_ident
refers to the ink! constructor or message identifier.
Inherent Implementation Blocks
For inherent implementation blocks, when trait_prefix
is None
the composed
selector is computed as follows:
- Apply
BLAKE2
256-bit hashH
on the bytes of the ASCII representation of thefn_ident
identifier. - The first 4 bytes of
H
make up the selector.
Trait Implementation Blocks
For trait implementation blocks, when trait_prefix
is
Some((namespace, trait_ident))
the composed selector is computed as follows:
- Compute the ASCII byte representation of
fn_ident
and call itF
. - Compute the ASCII byte representation of
namespace
and call itN
. - Compute the ASCII byte representation of
trait_ident
and call itT
. - Concatenate
N
,T
andF
using::
as separator and call itC
. - Apply the
BLAKE2
256-bit hashH
ofC
. - The first 4 bytes of
H
make up the selector.
sourcepub fn into_be_u32(self) -> u32
pub fn into_be_u32(self) -> u32
Returns the big-endian u32
representation of the selector bytes.
Trait Implementations
sourceimpl Ord for Selector
impl Ord for Selector
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialOrd<Selector> for Selector
impl PartialOrd<Selector> for Selector
sourcefn partial_cmp(&self, other: &Selector) -> Option<Ordering>
fn partial_cmp(&self, other: &Selector) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Selector
impl Eq for Selector
impl StructuralEq for Selector
impl StructuralPartialEq for Selector
Auto Trait Implementations
impl RefUnwindSafe for Selector
impl Send for Selector
impl Sync for Selector
impl Unpin for Selector
impl UnwindSafe for Selector
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more