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
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl 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>,
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
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>
sourceimpl JsonSchema for SubMsgResult
impl JsonSchema for SubMsgResult
sourcefn schema_name() -> String
fn schema_name() -> String
sourcefn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
sourcefn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read more