pub struct ChainExtensionMethod<I, O, ErrorCode, const IS_RESULT: bool> { /* private fields */ }
Expand description

A concrete instance of a chain extension method.

This is a utility type used to drive the execution of a chain extension method call. It has several specializations of its call method for different ways to manage error handling when calling a predefined chain extension method.

  • I represents the input type of the chain extension method. All tuple types that may act as input parameters for the chain extension method are valid. Examples include (), i32, (u8, [u8; 5], i32), etc.
  • O represents the return (or output) type of the chain extension method.
  • ErrorCode represents how the chain extension method handles the chain extension’s error code. Only HandleErrorCode<E> and IgnoreErrorCode types are allowed that each say to either properly handle or ignore the chain extension’s error code respectively.
  • const IS_RESULT: bool indicates if the O (output type) is of Result<T, E> type.

The type states for type parameter O and ErrorCode represent 4 different states:

  1. The chain extension method makes use of the chain extension’s error code: HandleErrorCode(E)
    • A: The chain extension method returns a Result<T, E> type, i.e. IS_RESULT is set to true.
    • B: The chain extension method returns a type O that is not a Result type. The return type is still wrapped into Result<O, E>
  2. The chain extension ignores the chain extension’s error code: IgnoreErrorCode
    • A: The chain extension method returns a Result<T, E> type, i.e. IS_RESULT is set to true.
    • B: The chain extension method returns a type O that is not a Result type. The method just returns O.

Implementations§

source§

impl ChainExtensionMethod<(), (), (), false>

source

pub fn build(id: u32) -> Self

Creates a new chain extension method instance.

source§

impl<O, ErrorCode, const IS_RESULT: bool> ChainExtensionMethod<(), O, ErrorCode, IS_RESULT>

source

pub fn input<I>(self) -> ChainExtensionMethod<I, O, ErrorCode, IS_RESULT>where I: Encode,

Sets the input types of the chain extension method call to I.

Note

I represents the input type of the chain extension method. All tuple types that may act as input parameters for the chain extension method are valid. Examples include (), i32, (u8, [u8; 5], i32), etc.

source§

impl<I, ErrorCode> ChainExtensionMethod<I, (), ErrorCode, false>

source

pub fn output<O, const IS_RESULT: bool>( self ) -> ChainExtensionMethod<I, O, ErrorCode, IS_RESULT>where O: Decode,

Sets the output type, O, of the chain extension method call.

If const IS_RESULT: bool is set to true, O is treated as Result<T, E>

Note

If O is incorrectly indicated as Return<T, E>, the type will not satisfy trait bounds later in method builder pipeline.

source§

impl<I, O, const IS_RESULT: bool> ChainExtensionMethod<I, O, (), IS_RESULT>

source

pub fn ignore_error_code( self ) -> ChainExtensionMethod<I, O, IgnoreErrorCode, IS_RESULT>

Makes the chain extension method call assume that the returned status code is always success.

Note

This will avoid handling of failure status codes returned by the chain extension method call. Use this only if you are sure that the chain extension method call will never return an error code that represents failure.

The output of the chain extension method call is always decoded and returned in this case.

source

pub fn handle_error_code<ErrorCode>( self ) -> ChainExtensionMethod<I, O, HandleErrorCode<ErrorCode>, IS_RESULT>where ErrorCode: FromStatusCode,

Makes the chain extension method call handle the returned status code.

Note

This will handle the returned status code and only loads and decodes the value returned as the output of the chain extension method call in case of success.

source§

impl<I, O, ErrorCode> ChainExtensionMethod<I, O, HandleErrorCode<ErrorCode>, true>where O: IsResultType, I: Encode, <O as IsResultType>::Ok: Decode, <O as IsResultType>::Err: Decode + From<ErrorCode> + From<Error>, ErrorCode: FromStatusCode,

source

pub fn call( self, input: &I ) -> Result<<O as IsResultType>::Ok, <O as IsResultType>::Err>

Calls the chain extension method for case 1.A described here.

Errors
  • If the called chain extension method returns a non-successful error code.
  • If the Result return value of the called chain extension represents an error.
  • If the Result return value cannot be SCALE decoded properly.
  • If custom constraints specified by the called chain extension method are violated.
    • These constraints are determined and defined by the author of the chain extension method.
Example

Declares a chain extension method with the unique ID of 5 that requires a bool and an i32 as input parameters and returns a Result<i32, MyError> upon completion. Note how we set const constant argument to true to indicate that return type is Result<T, E>. It will handle the shared error code from the chain extension. The call is finally invoked with arguments true and 42 for the bool and i32 input parameter respectively.

let result = ChainExtensionMethod::build(5)
    .input::<(bool, i32)>()
    .output::<Result<i32, MyError>, true>()
    .handle_error_code::<MyErrorCode>()
    .call(&(true, 42));
source§

impl<I, O> ChainExtensionMethod<I, O, IgnoreErrorCode, true>where O: IsResultType, I: Encode, <O as IsResultType>::Ok: Decode, <O as IsResultType>::Err: Decode + From<Error>,

source

pub fn call( self, input: &I ) -> Result<<O as IsResultType>::Ok, <O as IsResultType>::Err>

Calls the chain extension method for case 2.A described here.

Errors
  • If the Result return value of the called chain extension represents an error.
  • If the Result return value cannot be SCALE decoded properly.
  • If custom constraints specified by the called chain extension method are violated.
    • These constraints are determined and defined by the author of the chain extension method.
Example

Declares a chain extension method with the unique ID of 5 that requires a bool and an i32 as input parameters and returns a Result<i32, MyError> upon completion. Note how we set const constant argument to true to indicate that return type is Result<T, E>. It will ignore the shared error code from the chain extension and assumes that the call succeeds. The call is finally invoked with arguments true and 42 for the bool and i32 input parameter respectively.

let result = ChainExtensionMethod::build(5)
    .input::<(bool, i32)>()
    .output::<Result<i32, MyError>, true>()
    .ignore_error_code()
    .call(&(true, 42));
source§

impl<I, O, ErrorCode> ChainExtensionMethod<I, O, HandleErrorCode<ErrorCode>, false>where I: Encode, O: Decode, ErrorCode: FromStatusCode,

source

pub fn call(self, input: &I) -> Result<O, ErrorCode>

Calls the chain extension method for case 1.B described here.

Errors
  • If the called chain extension method returns a non-successful error code.
  • If custom constraints specified by the called chain extension method are violated.
    • These constraints are determined and defined by the author of the chain extension method.
Panics
  • If the return value cannot be SCALE decoded properly.
Example

Declares a chain extension method with the unique ID of 5 that requires a bool and an i32 as input parameters and returns a Result<i32, MyErrorCode> upon completion, because handle_status flag is set. We still need to indicate that the original type is not Result<T, E>, so const IS_RESULT is set false. It will handle the shared error code from the chain extension. The call is finally invoked with arguments true and 42 for the bool and i32 input parameter respectively.

let result = ChainExtensionMethod::build(5)
    .input::<(bool, i32)>()
    .output::<i32, false>()
    .handle_error_code::<MyErrorCode>()
    .call(&(true, 42));
source§

impl<I, O> ChainExtensionMethod<I, O, IgnoreErrorCode, false>where I: Encode, O: Decode,

source

pub fn call(self, input: &I) -> O

Calls the chain extension method for case 2.B described here.

Panics
  • If the return value cannot be SCALE decoded properly.
Example

Declares a chain extension method with the unique ID of 5 that requires a bool and an i32 as input parameters and returns a i32 upon completion. Hence, const IS_RESULT is set false. It will ignore the shared error code from the chain extension and assumes that the call succeeds. The call is finally invoked with arguments true and 42 for the bool and i32 input parameter respectively.

let result = ChainExtensionMethod::build(5)
    .input::<(bool, i32)>()
    .output::<i32, false>()
    .ignore_error_code()
    .call(&(true, 42));

Trait Implementations§

source§

impl<I: Debug, O: Debug, ErrorCode: Debug, const IS_RESULT: bool> Debug for ChainExtensionMethod<I, O, ErrorCode, IS_RESULT>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<I, O, ErrorCode, const IS_RESULT: bool> RefUnwindSafe for ChainExtensionMethod<I, O, ErrorCode, IS_RESULT>

§

impl<I, O, ErrorCode, const IS_RESULT: bool> Send for ChainExtensionMethod<I, O, ErrorCode, IS_RESULT>

§

impl<I, O, ErrorCode, const IS_RESULT: bool> Sync for ChainExtensionMethod<I, O, ErrorCode, IS_RESULT>

§

impl<I, O, ErrorCode, const IS_RESULT: bool> Unpin for ChainExtensionMethod<I, O, ErrorCode, IS_RESULT>

§

impl<I, O, ErrorCode, const IS_RESULT: bool> UnwindSafe for ChainExtensionMethod<I, O, ErrorCode, IS_RESULT>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Conv for T

§

fn conv<T>(self) -> Twhere Self: Into<T>,

Converts self into T using Into<T>. Read more
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pipe for Twhere T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> Rwhere Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R ) -> Rwhere Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V