[−][src]Enum cosmwasm_std::ContractResult
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
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]
pub fn clone(&self) -> ContractResult<S>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<S: Debug> Debug for ContractResult<S>
[src]
impl<'de, S> Deserialize<'de> for ContractResult<S> where
S: Deserialize<'de>,
[src]
S: Deserialize<'de>,
pub fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<S> From<ContractResult<S>> for Result<S, String>
[src]
pub fn from(original: ContractResult<S>) -> Result<S, String>
[src]
impl<S, E: ToString> From<Result<S, E>> for ContractResult<S>
[src]
pub fn from(original: Result<S, E>) -> ContractResult<S>
[src]
impl<S: JsonSchema> JsonSchema for ContractResult<S>
[src]
pub fn schema_name() -> String
[src]
pub fn json_schema(gen: &mut SchemaGenerator) -> Schema
[src]
pub fn is_referenceable() -> bool
[src]
impl<S: PartialEq> PartialEq<ContractResult<S>> for ContractResult<S>
[src]
pub fn eq(&self, other: &ContractResult<S>) -> bool
[src]
pub fn ne(&self, other: &ContractResult<S>) -> bool
[src]
impl<S> Serialize for ContractResult<S> where
S: Serialize,
[src]
S: Serialize,
pub fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<S> StructuralPartialEq for ContractResult<S>
[src]
Auto Trait Implementations
impl<S> RefUnwindSafe for ContractResult<S> where
S: RefUnwindSafe,
S: RefUnwindSafe,
impl<S> Send for ContractResult<S> where
S: Send,
S: Send,
impl<S> Sync for ContractResult<S> where
S: Sync,
S: Sync,
impl<S> Unpin for ContractResult<S> where
S: Unpin,
S: Unpin,
impl<S> UnwindSafe for ContractResult<S> where
S: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,