Enum cosmwasm_std::ContractResult
source · [−]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)
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
sourceimpl<S> ContractResult<S>
impl<S> ContractResult<S>
sourceimpl<S: Debug> ContractResult<S>
impl<S: Debug> ContractResult<S>
pub fn unwrap_err(self) -> String
Trait Implementations
sourceimpl<S: Clone> Clone for ContractResult<S>
impl<S: Clone> Clone for ContractResult<S>
sourcefn clone(&self) -> ContractResult<S>
fn clone(&self) -> ContractResult<S>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<S: Debug> Debug for ContractResult<S>
impl<S: Debug> Debug for ContractResult<S>
sourceimpl<'de, S> Deserialize<'de> for ContractResult<S> where
S: Deserialize<'de>,
impl<'de, S> Deserialize<'de> for ContractResult<S> where
S: Deserialize<'de>,
sourcefn 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
sourceimpl<S> From<ContractResult<S>> for Result<S, String>
impl<S> From<ContractResult<S>> for Result<S, String>
sourcefn from(original: ContractResult<S>) -> Result<S, String>
fn from(original: ContractResult<S>) -> Result<S, String>
Performs the conversion.
sourceimpl<S, E: ToString> From<Result<S, E>> for ContractResult<S>
impl<S, E: ToString> From<Result<S, E>> for ContractResult<S>
sourcefn from(original: Result<S, E>) -> ContractResult<S>
fn from(original: Result<S, E>) -> ContractResult<S>
Performs the conversion.
sourceimpl<S: JsonSchema> JsonSchema for ContractResult<S>
impl<S: JsonSchema> JsonSchema for ContractResult<S>
sourcefn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
sourcefn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
sourcefn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the $ref
keyword. Read more
sourceimpl<S: PartialEq> PartialEq<ContractResult<S>> for ContractResult<S>
impl<S: PartialEq> PartialEq<ContractResult<S>> for ContractResult<S>
sourcefn eq(&self, other: &ContractResult<S>) -> bool
fn eq(&self, other: &ContractResult<S>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &ContractResult<S>) -> bool
fn ne(&self, other: &ContractResult<S>) -> bool
This method tests for !=
.
sourceimpl<S> Serialize for ContractResult<S> where
S: Serialize,
impl<S> Serialize for ContractResult<S> where
S: Serialize,
impl<S> StructuralPartialEq for ContractResult<S>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more