Enum cosmwasm_std::SubMsgResult
source · [−]pub enum SubMsgResult {
Ok(SubMsgResponse),
Err(String),
}
Expand description
This is the result type that is returned from a sub message execution.
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.
Until version 1.0.0-beta5, ContractResult<SubMsgResponse>
was used instead
of this type. Once serialized, the two types are the same. However, in the Rust type
system we want different types for clarity and documenation reasons.
Examples
Success:
let response = SubMsgResponse {
data: Some(Binary::from_base64("MTIzCg==").unwrap()),
events: vec![Event::new("wasm").add_attribute("fo", "ba")],
};
let result: SubMsgResult = SubMsgResult::Ok(response);
assert_eq!(to_vec(&result).unwrap(), br#"{"ok":{"events":[{"type":"wasm","attributes":[{"key":"fo","value":"ba"}]}],"data":"MTIzCg=="}}"#);
Failure:
let error_msg = String::from("Something went wrong");
let result = SubMsgResult::Err(error_msg);
assert_eq!(to_vec(&result).unwrap(), br#"{"error":"Something went wrong"}"#);
Variants
Ok(SubMsgResponse)
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 SubMsgResult
impl SubMsgResult
sourcepub fn into_result(self) -> Result<SubMsgResponse, String>
pub fn into_result(self) -> Result<SubMsgResponse, String>
Converts a SubMsgResult<S>
to a Result<S, String>
as a convenient way
to access the full Result API.
pub fn unwrap(self) -> SubMsgResponse
pub fn unwrap_err(self) -> String
pub fn is_ok(&self) -> bool
pub fn is_err(&self) -> bool
Trait Implementations
sourceimpl Clone for SubMsgResult
impl Clone for SubMsgResult
sourcefn clone(&self) -> SubMsgResult
fn clone(&self) -> SubMsgResult
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 Debug for SubMsgResult
impl Debug for SubMsgResult
sourceimpl<'de> Deserialize<'de> for SubMsgResult
impl<'de> Deserialize<'de> for SubMsgResult
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<E: ToString> From<Result<SubMsgResponse, E>> for SubMsgResult
impl<E: ToString> From<Result<SubMsgResponse, E>> for SubMsgResult
sourcefn from(original: Result<SubMsgResponse, E>) -> SubMsgResult
fn from(original: Result<SubMsgResponse, E>) -> SubMsgResult
Converts to this type from the input type.
sourceimpl From<SubMsgResult> for Result<SubMsgResponse, String>
impl From<SubMsgResult> for Result<SubMsgResponse, String>
sourcefn from(original: SubMsgResult) -> Result<SubMsgResponse, String>
fn from(original: SubMsgResult) -> Result<SubMsgResponse, String>
Converts to this type from the input type.
sourceimpl JsonSchema for SubMsgResult
impl JsonSchema for SubMsgResult
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 PartialEq<SubMsgResult> for SubMsgResult
impl PartialEq<SubMsgResult> for SubMsgResult
sourcefn eq(&self, other: &SubMsgResult) -> bool
fn eq(&self, other: &SubMsgResult) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &SubMsgResult) -> bool
fn ne(&self, other: &SubMsgResult) -> bool
This method tests for !=
.
sourceimpl Serialize for SubMsgResult
impl Serialize for SubMsgResult
impl StructuralPartialEq for SubMsgResult
Auto Trait Implementations
impl RefUnwindSafe for SubMsgResult
impl Send for SubMsgResult
impl Sync for SubMsgResult
impl Unpin for SubMsgResult
impl UnwindSafe for SubMsgResult
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
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.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more