#[command]Expand description
Marks a function as a Telepath RPC command.
§What it generates
For every annotated function the macro emits five additional items:
fn __telepath_shim_<name>(input: &[u8], output: &mut [u8], resources: &ResourceRegistry) -> Result<DispatchOutcome, DispatchError>— deserializesinputvia postcard, resolves#[resource]-annotated arguments fromresources, calls the original function, and serializes the result intooutput.fn __telepath_args_schema_<name>(out: &mut [u8]) -> Result<usize, ()>— writes a postcard-encodedpostcard_schema::schema::NamedTypefor the argument tuple intooutand returns the byte count.fn __telepath_ret_schema_<name>(out: &mut [u8]) -> Result<usize, ()>— same for the return type.pub const __TELEPATH_CMD_<NAME>: CommandMetadata— aCommandMetadataconst whoseidis derived deterministically from the function’s signature viaderive_cmd_idat build time.#[linkme] static __TELEPATH_REG_<NAME>— registers the metadata in [telepath_server::TELEPATH_COMMANDS] at link time.
The original function body is preserved unchanged so it remains directly callable.
§Requirements on the calling crate
The calling crate must declare the following direct dependencies:
telepath-server— providesCommandMetadata,DispatchError, and re-exportspostcard_schemaandlinkmefor use in generated code.postcard— used in the generated shim for (de)serialization
All argument types and the return type must implement
postcard_schema::Schema. Built-in primitives (u8, u32, (),
standard tuples, etc.) already implement it. For user-defined types,
add #[derive(postcard_schema::Schema)].
§Restrictions
The macro rejects functions that are:
async fn(RPC dispatch is synchronous)unsafe fn- Generic (
<T>/whereclauses) - Methods (
selfreceiver) - Functions with reference arguments or reference return types
- Functions with pattern-destructured arguments
§Example
ⓘ
use telepath_server::{command, CommandMetadata};
#[command]
fn ping() -> u32 {
0xDEAD_BEEF
}
static COMMANDS: [CommandMetadata; 1] = [__TELEPATH_CMD_PING];