DecodeCandid

Trait DecodeCandid 

Source
pub trait DecodeCandid {
    // Required method
    fn decode_candid<T>(self) -> Result<T, String>
       where T: CandidType + for<'de> Deserialize<'de>;
}
Expand description

Extension trait for decoding Candid responses from inter-canister calls.

This trait provides a convenient method to decode the response of an inter-canister call into a Rust type, combining error handling for both call failures and decoding failures.

Required Methods§

Source

fn decode_candid<T>(self) -> Result<T, String>
where T: CandidType + for<'de> Deserialize<'de>,

Decodes the response as a Candid type.

This method handles both the call result and Candid decoding in a single step, converting any errors into descriptive string messages.

§Type Parameters
  • T - The type to decode the response into. Must implement CandidType and Deserialize.
§Returns
  • Ok(T) - The successfully decoded response.
  • Err(String) - An error message describing either the call failure or decoding failure.
§Examples
let result: u32 = Call::bounded_wait(canister_id, "get_value")
    .await
    .decode_candid()?;

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.

Implementations on Foreign Types§

Source§

impl DecodeCandid for Result<Response, CallFailed>

Source§

fn decode_candid<T>(self) -> Result<T, String>
where T: CandidType + for<'de> Deserialize<'de>,

Implementors§