pub trait CustomMsg:
Serialize
+ Clone
+ Debug
+ PartialEq
+ JsonSchema { }
Expand description
A trait for custom message types which are embedded in CosmosMsg::Custom(..)
.
Those are messages that the contract and the chain need
to agree on in advance as the chain must be able to deserialize and execute them.
Custom messages are always JSON-encoded when sent from the contract to the environment.
This trait is similar to CustomQuery
for better type clarity and
makes it shorter to use as a trait bound. It does not require fields or functions to be implemented.
An alternative approach is using CosmosMsg::Any
which provides more flexibility but offers less type-safety.
§Examples
Some real-world examples of such custom message types are TgradeMsg, ArchwayMsg or NeutronMsg.
use cosmwasm_schema::cw_serde;
use cosmwasm_std::CustomQuery;
#[cw_serde]
pub enum MyMsg {
// ...
}
impl CustomQuery for MyMsg {}
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.