Method

Struct Method 

Source
pub struct Method { /* private fields */ }
Expand description

A method that is constructed using nested calls.

Implementations§

Source§

impl Method

Source

pub const fn new() -> Self

Create a new method.

Source

pub fn name<S: Into<String>>(self, name: S) -> Self

Put a name for the method. Setting a name on the method makes the CallHandler for this method skip this method if it’s trying to make a call to a method with a different name.

§Panics

If the method already has a name.

Source

pub fn cycles_consume_all(self) -> Self

Make the method consume all of the cycles provided to it.

Source

pub fn cycles_consume(self, cycles: u64) -> Self

Make the method consume at most the given amount of cycles.

Source

pub fn cycles_refund(self, cycles: u64) -> Self

Make the method refund the given amount of cycles.

Source

pub fn expect_arguments<T: ArgumentEncoder>(self, arguments: T) -> Self

Make the method expect the given value as the argument, this method makes the method panic if it’s called with an argument other than what is provided.

§Panics

If called more than once.

Source

pub fn expect_cycles(self, cycles: u64) -> Self

Create a method that expects this amount of cycles to be sent to it.

§Panics

If called more than once on a method.

Source

pub fn response<T: CandidType>(self, value: T) -> Self

Make the method return the given constant value every time.

§Panics

If called more than once.

Trait Implementations§

Source§

impl CallHandler for Method

Source§

fn accept(&self, _: &Principal, method: &str) -> bool

Whatever the handler can handle the given call or not, if this method returns false, we skip this handler and try to find the next handler that can handle the call.
Source§

fn perform( &self, _caller: &Principal, cycles: u64, _canister_id: &Principal, _method: &str, args_raw: &Vec<u8>, ctx: Option<&mut MockContext>, ) -> (CallResult<Vec<u8>>, u64)

Perform the call using this handler. Only called if accept() first returned true.

Auto Trait Implementations§

§

impl Freeze for Method

§

impl RefUnwindSafe for Method

§

impl Send for Method

§

impl Sync for Method

§

impl Unpin for Method

§

impl UnwindSafe for Method

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. 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 T
where 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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.