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}}"#);
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"}"#);
Variants§
Ok(S)
Err(String)
An error type that every custom error created by contract developers can be converted to. This could potentially have more structure, but String is the easiest.
Implementations§
Source§impl<S> ContractResult<S>
impl<S> ContractResult<S>
Source§impl<S: Debug> ContractResult<S>
impl<S: Debug> ContractResult<S>
pub fn unwrap_err(self) -> String
Trait Implementations§
Source§impl<S: Clone> Clone for ContractResult<S>
impl<S: Clone> Clone for ContractResult<S>
Source§fn clone(&self) -> ContractResult<S>
fn clone(&self) -> ContractResult<S>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<S: Debug> Debug for ContractResult<S>
impl<S: Debug> Debug for ContractResult<S>
Source§impl<'de, S> Deserialize<'de> for ContractResult<S>where
S: Deserialize<'de>,
impl<'de, S> Deserialize<'de> for ContractResult<S>where
S: Deserialize<'de>,
Source§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
Source§impl<S, E: ToString> From<Result<S, E>> for ContractResult<S>
impl<S, E: ToString> From<Result<S, E>> for ContractResult<S>
Source§fn from(original: Result<S, E>) -> ContractResult<S>
fn from(original: Result<S, E>) -> ContractResult<S>
Converts to this type from the input type.
Source§impl<S: JsonSchema> JsonSchema for ContractResult<S>
impl<S: JsonSchema> JsonSchema for ContractResult<S>
Source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn 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 moreSource§impl<S: PartialEq> PartialEq for ContractResult<S>
impl<S: PartialEq> PartialEq for ContractResult<S>
Source§impl<S> Serialize for ContractResult<S>where
S: Serialize,
impl<S> Serialize for ContractResult<S>where
S: Serialize,
impl<S: Eq> Eq for ContractResult<S>
impl<S> StructuralPartialEq for ContractResult<S>
Auto Trait Implementations§
impl<S> Freeze for ContractResult<S>where
S: Freeze,
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more