pub struct DynCommand<Req, Res, F> { /* private fields */ }Expand description
A runtime-constructed Command. Use this when the command id
or schema is only known at runtime (plugin runtimes, FFI,
scripting hosts).
§Example — dynamic id with Value payloads
use coralstack_cmd_ipc::prelude::*;
use serde_json::{json, Value};
let cmd = DynCommand::new("plugin.say_hi", |_req: Value| async move {
Ok(json!({ "greeting": "hello" }))
});
registry.register_command(cmd).await?;§Example — dynamic id with typed payloads
#[derive(serde::Deserialize)]
struct AddReq { a: i64, b: i64 }
let cmd = DynCommand::new(runtime_id, |req: AddReq| async move {
Ok(req.a + req.b)
})
.description("Runtime-registered adder");
registry.register_command(cmd).await?;Implementations§
Source§impl<Req, Res, F, Fut> DynCommand<Req, Res, F>
impl<Req, Res, F, Fut> DynCommand<Req, Res, F>
Sourcepub fn new(id: impl Into<String>, handler: F) -> Self
pub fn new(id: impl Into<String>, handler: F) -> Self
Build a new dynamic command. The request/response types are
inferred from the handler’s signature; annotate them if type
inference needs help (commonly |req: Value| for fully
dynamic payloads).
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Attach a human-readable description, surfaced via
Command::description and forwarded to MCP/tooling consumers.
Sourcepub fn schema(self, schema: CommandSchema) -> Self
pub fn schema(self, schema: CommandSchema) -> Self
Attach a full CommandSchema (both request + response slots)
advertised on the wire via register.command.request. Omit to
register without a schema (peers will fall back to permissive
validation).
Sourcepub fn request_schema(self, schema: Value) -> Self
pub fn request_schema(self, schema: Value) -> Self
Attach only the request schema. Convenient when your runtime introspection knows the argument shape but not the return.
Sourcepub fn response_schema(self, schema: Value) -> Self
pub fn response_schema(self, schema: Value) -> Self
Attach only the response schema.
Source§impl DynCommand<Value, Value, BoxedHandler>
impl DynCommand<Value, Value, BoxedHandler>
Sourcepub fn boxed<F, Fut>(id: impl Into<String>, handler: F) -> BoxedDynCommand
pub fn boxed<F, Fut>(id: impl Into<String>, handler: F) -> BoxedDynCommand
Construct a BoxedDynCommand from any async closure producing
a Result<Value, CommandError>. The handler’s future is boxed so
the resulting command has a single concrete type, making it
suitable for heterogeneous collections.
use coralstack_cmd_ipc::prelude::*;
use coralstack_cmd_ipc::BoxedDynCommand;
use serde_json::{json, Value};
let cmd: BoxedDynCommand = DynCommand::boxed("plugin.hello", |req| async move {
Ok(json!({ "you_sent": req }))
});
registry.register_command(cmd).await?;Trait Implementations§
Source§impl<Req, Res, F, Fut> Command for DynCommand<Req, Res, F>
impl<Req, Res, F, Fut> Command for DynCommand<Req, Res, F>
Source§const ID: &'static str = ""
const ID: &'static str = ""
id to return a runtime string
(as DynCommand does). Read moretype Request = Req
type Response = Res
Source§fn id(&self) -> &str
fn id(&self) -> &str
ID.
DynCommand overrides this to return a runtime-owned id.Source§fn description(&self) -> Option<&str>
fn description(&self) -> Option<&str>
DESCRIPTION.Source§fn schema(&self) -> Option<CommandSchema>
fn schema(&self) -> Option<CommandSchema>
Source§fn handle(
&self,
request: Req,
) -> impl Future<Output = Result<Res, CommandError>> + Send
fn handle( &self, request: Req, ) -> impl Future<Output = Result<Res, CommandError>> + Send
Source§const DESCRIPTION: Option<&'static str> = None
const DESCRIPTION: Option<&'static str> = None
description is overridden.