pub trait ClusterCommand:
Send
+ Sync
+ 'static {
type Input: Serialize + DeserializeOwned + Send + 'static;
type Output: Serialize + DeserializeOwned + Send + 'static;
const NAME: &'static str;
}Expand description
A command that clusters handle by name, with typed input and output (D-286, D-308): the
typed replacement for discord.js’s broadcastEval, which Rust cannot do (there is no
code to evaluate at run time).
Implement it on a type of your own, in the code that both the manager and the cluster
processes run (D-296: they are the same executable), so the name and the types cannot
disagree. A cluster handles it with
ClusterClient::handle; the manager and the clusters send
it with broadcast (every cluster) or
send (one), and the same methods on
ClusterManager. The input and output cross the processes as
JSON.
discord.js counterpart: the function given to broadcastEval.
§Examples
use djs_rs::sharding::ClusterCommand;
/// How many guilds a cluster has in its cache.
struct GuildCount;
impl ClusterCommand for GuildCount {
const NAME: &'static str = "guild_count";
type Input = ();
type Output = usize;
}Required Associated Constants§
Required Associated Types§
Sourcetype Input: Serialize + DeserializeOwned + Send + 'static
type Input: Serialize + DeserializeOwned + Send + 'static
What the sender gives the handler.
Sourcetype Output: Serialize + DeserializeOwned + Send + 'static
type Output: Serialize + DeserializeOwned + Send + 'static
What the handler returns to the sender.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".