Enum cosmwasm_std::ContractResult [−][src]
pub enum ContractResult<S> {
Ok(S),
Err(String),
}
Expand description
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":{"messages":[],"attributes":[],"events":[],"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)
Tuple Fields
0: 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
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Performs the conversion.
Performs the conversion.
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
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
Mutably borrows from an owned value. Read more