Enum cosmwasm_std::ContractResult[][src]

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/execute/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: Response = Response::default();
let result: ContractResult<Response> = ContractResult::Ok(response);
assert_eq!(to_vec(&result).unwrap(), br#"{"ok":{"submessages":[],"messages":[],"attributes":[],"data":null}}"#.to_vec());

Failure:

let error_msg = String::from("Something went wrong");
let result: ContractResult<Response> = 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]

pub fn is_ok(&self) -> bool[src]

pub fn is_err(&self) -> bool[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, 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> Conv for T

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

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

impl<T> FmtForward for T

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

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

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

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.