pub trait Context {
Show 32 methods
// Required methods
fn trap(&self, message: &str) -> !;
fn print<S: AsRef<str>>(&self, s: S);
fn id(&self) -> Principal;
fn time(&self) -> u64;
fn balance(&self) -> u64;
fn caller(&self) -> Principal;
fn msg_cycles_available(&self) -> u64;
fn msg_cycles_accept(&self, amount: u64) -> u64;
fn msg_cycles_refunded(&self) -> u64;
fn stable_store<T>(&self, data: T) -> Result<(), Error>
where T: ArgumentEncoder;
fn stable_restore<T>(&self) -> Result<T, String>
where T: for<'de> ArgumentDecoder<'de>;
fn call_raw<S: Into<String>>(
&'static self,
id: Principal,
method: S,
args_raw: Vec<u8>,
cycles: u64,
) -> CallResponse<Vec<u8>>;
fn set_certified_data(&self, data: &[u8]);
fn data_certificate(&self) -> Option<Vec<u8>>;
fn spawn<F: 'static + Future<Output = ()>>(&mut self, future: F);
fn stable_size(&self) -> u32;
fn stable_grow(&self, new_pages: u32) -> Result<u32, StableMemoryError>;
fn stable_write(&self, offset: u32, buf: &[u8]);
fn stable_read(&self, offset: u32, buf: &mut [u8]);
fn with<T: 'static + Default, U, F: FnOnce(&T) -> U>(
&self,
callback: F,
) -> U;
fn maybe_with<T: 'static, U, F: FnOnce(&T) -> U>(
&self,
callback: F,
) -> Option<U>;
fn with_mut<T: 'static + Default, U, F: FnOnce(&mut T) -> U>(
&self,
callback: F,
) -> U;
fn maybe_with_mut<T: 'static, U, F: FnOnce(&mut T) -> U>(
&self,
callback: F,
) -> Option<U>;
fn take<T: 'static>(&self) -> Option<T>;
fn swap<T: 'static>(&self, value: T) -> Option<T>;
fn store<T: 'static>(&self, data: T);
fn get_maybe<T: 'static>(&self) -> Option<&T>;
fn get<T: 'static + Default>(&self) -> &T;
fn get_mut<T: 'static + Default>(&self) -> &mut T;
fn delete<T: 'static + Default>(&self) -> bool;
// Provided methods
fn call<T: ArgumentEncoder, R: for<'a> ArgumentDecoder<'a>, S: Into<String>>(
&'static self,
id: Principal,
method: S,
args: T,
) -> CallResponse<R> { ... }
fn call_with_payment<T: ArgumentEncoder, R: for<'a> ArgumentDecoder<'a>, S: Into<String>>(
&'static self,
id: Principal,
method: S,
args: T,
cycles: u64,
) -> CallResponse<R> { ... }
}Required Methods§
Sourcefn msg_cycles_available(&self) -> u64
fn msg_cycles_available(&self) -> u64
Return the number of available cycles that is sent by the caller.
Sourcefn msg_cycles_accept(&self, amount: u64) -> u64
fn msg_cycles_accept(&self, amount: u64) -> u64
Accept the given amount of cycles, returns the actual amount of accepted cycles.
Sourcefn msg_cycles_refunded(&self) -> u64
fn msg_cycles_refunded(&self) -> u64
Return the cycles that were sent back by the canister that was just called. This method should only be called right after an inter-canister call.
Sourcefn stable_store<T>(&self, data: T) -> Result<(), Error>where
T: ArgumentEncoder,
fn stable_store<T>(&self, data: T) -> Result<(), Error>where
T: ArgumentEncoder,
Store the given data to the stable storage.
Sourcefn stable_restore<T>(&self) -> Result<T, String>where
T: for<'de> ArgumentDecoder<'de>,
fn stable_restore<T>(&self) -> Result<T, String>where
T: for<'de> ArgumentDecoder<'de>,
Restore the data from the stable storage. If the data is not already stored the None value is returned.
Sourcefn call_raw<S: Into<String>>(
&'static self,
id: Principal,
method: S,
args_raw: Vec<u8>,
cycles: u64,
) -> CallResponse<Vec<u8>>
fn call_raw<S: Into<String>>( &'static self, id: Principal, method: S, args_raw: Vec<u8>, cycles: u64, ) -> CallResponse<Vec<u8>>
Perform a call.
Sourcefn set_certified_data(&self, data: &[u8])
fn set_certified_data(&self, data: &[u8])
Set the certified data of the canister, this method traps if data.len > 32.
Sourcefn data_certificate(&self) -> Option<Vec<u8>>
fn data_certificate(&self) -> Option<Vec<u8>>
Returns the data certificate authenticating certified_data set by this canister.
Sourcefn spawn<F: 'static + Future<Output = ()>>(&mut self, future: F)
fn spawn<F: 'static + Future<Output = ()>>(&mut self, future: F)
Execute a future without blocking the current call.
Sourcefn stable_size(&self) -> u32
fn stable_size(&self) -> u32
Returns the current size of the stable memory in WebAssembly pages. (One WebAssembly page is 64KiB)
Sourcefn stable_grow(&self, new_pages: u32) -> Result<u32, StableMemoryError>
fn stable_grow(&self, new_pages: u32) -> Result<u32, StableMemoryError>
Tries to grow the memory by new_pages many pages containing zeroes. This system call traps if the previous size of the memory exceeds 2^32 bytes. Errors if the new size of the memory exceeds 2^32 bytes or growing is unsuccessful. Otherwise, it grows the memory and returns the previous size of the memory in pages.
Sourcefn stable_write(&self, offset: u32, buf: &[u8])
fn stable_write(&self, offset: u32, buf: &[u8])
Writes data to the stable memory location specified by an offset.
Sourcefn stable_read(&self, offset: u32, buf: &mut [u8])
fn stable_read(&self, offset: u32, buf: &mut [u8])
Reads data from the stable memory location specified by an offset.
Sourcefn with<T: 'static + Default, U, F: FnOnce(&T) -> U>(&self, callback: F) -> U
fn with<T: 'static + Default, U, F: FnOnce(&T) -> U>(&self, callback: F) -> U
Pass an immutable reference of data with type T to the callback, stores the default value
if not present, and return the transformation.
Sourcefn maybe_with<T: 'static, U, F: FnOnce(&T) -> U>(
&self,
callback: F,
) -> Option<U>
fn maybe_with<T: 'static, U, F: FnOnce(&T) -> U>( &self, callback: F, ) -> Option<U>
Pass an immutable reference of data with type T to the callback, and return the mapped
value.
Sourcefn with_mut<T: 'static + Default, U, F: FnOnce(&mut T) -> U>(
&self,
callback: F,
) -> U
fn with_mut<T: 'static + Default, U, F: FnOnce(&mut T) -> U>( &self, callback: F, ) -> U
Pass the mutable reference of data with type T to the callback, stores the default value
if not present, and return the transformation.
Sourcefn maybe_with_mut<T: 'static, U, F: FnOnce(&mut T) -> U>(
&self,
callback: F,
) -> Option<U>
fn maybe_with_mut<T: 'static, U, F: FnOnce(&mut T) -> U>( &self, callback: F, ) -> Option<U>
Pass the mutable reference of data with type T to the callback, and return the callback’s
result.
Sourcefn take<T: 'static>(&self) -> Option<T>
fn take<T: 'static>(&self) -> Option<T>
Remove the data associated with the given type, and return it.
Provided Methods§
Sourcefn call<T: ArgumentEncoder, R: for<'a> ArgumentDecoder<'a>, S: Into<String>>(
&'static self,
id: Principal,
method: S,
args: T,
) -> CallResponse<R>
fn call<T: ArgumentEncoder, R: for<'a> ArgumentDecoder<'a>, S: Into<String>>( &'static self, id: Principal, method: S, args: T, ) -> CallResponse<R>
Perform the call and return the response.
fn call_with_payment<T: ArgumentEncoder, R: for<'a> ArgumentDecoder<'a>, S: Into<String>>( &'static self, id: Principal, method: S, args: T, cycles: u64, ) -> CallResponse<R>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.