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 documentation reasons.
§Examples
Success:
#[allow(deprecated)]
let response = SubMsgResponse {
data: Some(Binary::from_base64("MTIzCg==").unwrap()),
events: vec![Event::new("wasm").add_attribute("foo", "bar")],
msg_responses: vec![],
};
let result: SubMsgResult = SubMsgResult::Ok(response);
assert_eq!(
to_json_string(&result).unwrap(),
r#"{"ok":{"events":[{"type":"wasm","attributes":[{"key":"foo","value":"bar"}]}],"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 potentially 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§impl Serialize for SubMsgResult
impl Serialize for SubMsgResult
impl Eq for SubMsgResult
impl StructuralPartialEq for SubMsgResult
Auto Trait Implementations§
impl Freeze for SubMsgResult
impl RefUnwindSafe for SubMsgResult
impl Send for SubMsgResult
impl Sync for SubMsgResult
impl Unpin for SubMsgResult
impl UnwindSafe for SubMsgResult
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
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>
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>
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