[][src]Enum cosmwasm_std::ContractResult

pub enum ContractResult<S> {
    Ok(S),
    Err(String),
}

This is the final result type that is created and serialized in a contract for every init/handle/migrate call. The VM then deserializes this type to distinguish between successful and failed executions.

We use a custom type here instead of Rust's Result because we want to be able to define the serialization, which is a public interface. Every language that compiles to Wasm and runs in the ComsWasm VM needs to create the same JSON representation.

Examples

Success:

let response: HandleResponse = HandleResponse::default();
let result: ContractResult<HandleResponse> = ContractResult::Ok(response);
assert_eq!(to_vec(&result).unwrap(), br#"{"ok":{"messages":[],"attributes":[],"data":null}}"#.to_vec());

Failure:

let error_msg = String::from("Something went wrong");
let result: ContractResult<HandleResponse> = ContractResult::Err(error_msg);
assert_eq!(to_vec(&result).unwrap(), br#"{"error":"Something went wrong"}"#.to_vec());

Variants

Ok(S)
Err(String)

An error type that every custom error created by contract developers can be converted to. This could potientially have more structure, but String is the easiest.

Implementations

impl<S> ContractResult<S>[src]

pub fn into_result(self) -> Result<S, String>[src]

Converts a ContractResult<S> to a Result<S, String> as a convenient way to access the full Result API.

pub fn unwrap(self) -> S[src]

impl<S: Debug> ContractResult<S>[src]

pub fn unwrap_err(self) -> String[src]

Trait Implementations

impl<S: Clone> Clone for ContractResult<S>[src]

impl<S: Debug> Debug for ContractResult<S>[src]

impl<'de, S> Deserialize<'de> for ContractResult<S> where
    S: Deserialize<'de>, 
[src]

impl<S> From<ContractResult<S>> for Result<S, String>[src]

impl<S, E: ToString> From<Result<S, E>> for ContractResult<S>[src]

impl<S: JsonSchema> JsonSchema for ContractResult<S>[src]

impl<S: PartialEq> PartialEq<ContractResult<S>> for ContractResult<S>[src]

impl<S> Serialize for ContractResult<S> where
    S: Serialize
[src]

impl<S> StructuralPartialEq for ContractResult<S>[src]

Auto Trait Implementations

impl<S> RefUnwindSafe for ContractResult<S> where
    S: RefUnwindSafe

impl<S> Send for ContractResult<S> where
    S: Send

impl<S> Sync for ContractResult<S> where
    S: Sync

impl<S> Unpin for ContractResult<S> where
    S: Unpin

impl<S> UnwindSafe for ContractResult<S> where
    S: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.