Skip to main content

ClusterCommand

Trait ClusterCommand 

Source
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§

Source

const NAME: &'static str

The name the command is sent and handled under; unique among a bot’s commands. Names starting with djs-rs: are reserved for the library’s own.

Required Associated Types§

Source

type Input: Serialize + DeserializeOwned + Send + 'static

What the sender gives the handler.

Source

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".

Implementors§

Source§

impl ClusterCommand for Stats

Source§

const NAME: &'static str = "djs-rs:stats"

Source§

type Input = ()

Source§

type Output = ClusterStats