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:
#[allow(deprecated)]
let response = SubMsgResponse {
data: Some(Binary::from_base64("MTIzCg==").unwrap()),
events: vec![Event::new("wasm").add_attribute("fo", "ba")],
msg_responses: vec![],
};
let result: SubMsgResult = SubMsgResult::Ok(response);
assert_eq!(
to_json_string(&result).unwrap(),
r#"{"ok":{"events":[{"type":"wasm","attributes":[{"key":"fo","value":"ba"}]}],"data":"MTIzCg==","msg_responses":[]}}"#,
);
Failure:
let error_msg = String::from("Something went wrong");
let result = SubMsgResult::Err(error_msg);
assert_eq!(to_json_string(&result).unwrap(), r#"{"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§
source§impl 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§
source§impl Clone for SubMsgResult
impl Clone for SubMsgResult
source§fn clone(&self) -> SubMsgResult
fn clone(&self) -> SubMsgResult
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SubMsgResult
impl Debug for SubMsgResult
source§impl<'de> Deserialize<'de> for SubMsgResult
impl<'de> Deserialize<'de> for SubMsgResult
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>,
source§impl<E: ToString> From<Result<SubMsgResponse, E>> for SubMsgResult
impl<E: ToString> From<Result<SubMsgResponse, E>> for SubMsgResult
source§fn from(original: Result<SubMsgResponse, E>) -> SubMsgResult
fn from(original: Result<SubMsgResponse, E>) -> SubMsgResult
source§impl From<SubMsgResult> for Result<SubMsgResponse, String>
impl From<SubMsgResult> for Result<SubMsgResponse, String>
source§fn from(original: SubMsgResult) -> Result<SubMsgResponse, String>
fn from(original: SubMsgResult) -> Result<SubMsgResponse, String>
source§impl JsonSchema for SubMsgResult
impl JsonSchema for SubMsgResult
source§fn schema_name() -> String
fn schema_name() -> String
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl PartialEq for SubMsgResult
impl PartialEq for SubMsgResult
source§fn eq(&self, other: &SubMsgResult) -> bool
fn eq(&self, other: &SubMsgResult) -> bool
self
and other
values to be equal, and is used
by ==
.