pub struct Selector { /* private fields */ }Expand description
The selector of an ink! dispatchable.
§Note
This is equal to the first four bytes of the BLAKE-2 256 hash of a function’s name.
Implementations§
Source§impl 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_name: String) -> Self
pub fn compose<'a, T>(trait_prefix: T, fn_name: String) -> Self
§Note
trait_prefixisNonewhen computing the selector of ink! constructors and messages in inherent implementation blocks.trait_prefixisSomewhen computing the selector of ink! constructors and messages in trait implementation blocks. In this case thenamespaceis 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_namespaceconcatenated with::and the identifier of the trait definition would then be part of the providedtrait_prefixparameter.fn_identrefers 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
BLAKE2256-bit hashHon the bytes of the ASCII representation of thefn_identidentifier. - The first 4 bytes of
Hmake 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_identand call itF. - Compute the ASCII byte representation of
namespaceand call itN. - Compute the ASCII byte representation of
trait_identand call itT. - Concatenate
N,TandFusing::as separator and call itC. - Apply the
BLAKE2256-bit hashHofC. - The first 4 bytes of
Hmake 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§
Source§impl Ord for Selector
impl Ord for Selector
Source§impl PartialOrd for Selector
impl PartialOrd for Selector
impl Copy for Selector
impl Eq for Selector
impl StructuralPartialEq for Selector
Auto Trait Implementations§
impl Freeze for Selector
impl RefUnwindSafe for Selector
impl Send for Selector
impl Sync for Selector
impl Unpin for Selector
impl UnwindSafe for Selector
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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