plexus-macros
Procedural macros for Plexus RPC activations.
What is Plexus RPC?
Plexus RPC is a protocol for building services with runtime schema introspection. Unlike traditional RPC systems that require separate schema definitions, Plexus RPC extracts schemas directly from your code at runtime. This ensures zero drift between your implementation and schema.
This crate provides macros to generate Plexus RPC-compatible activations from Rust code.
Overview
The #[hub_methods] macro transforms a standard Rust impl block into a fully-functional Plexus RPC activation. It automatically:
- Extracts method schemas from function signatures
- Generates method dispatch logic
- Implements the
Activationtrait for registry integration - Creates schema introspection endpoints
Your function signature is the schema - no separate IDL files needed.
Quick Start
use hub_methods;
use ;
use JsonSchema;
use Stream;
This generates:
- Method enum for schema extraction
- Activation trait implementation
- RPC server trait and dispatcher
- Schema introspection for
{backend}.schemacalls
Macro Attributes
#[hub_methods] - Impl Block Level
Marks an impl block as containing Plexus RPC methods.
Required:
namespace = "..."- The activation namespace (e.g., "bash", "arbor")
Optional:
version = "..."- Semantic version (default: "1.0.0")description = "..."- Human-readable descriptioncrate_path = "..."- Path to substrate crate (default: "crate")
#[hub_method] - Method Level
Marks an individual method as a Plexus RPC endpoint.
Features:
- Extracts method name from function name
- Extracts description from doc comments (
///) - Generates input schema from parameter types
- Generates output schema from return type
Requirements:
- Method must be
async - Must return
impl Stream<Item = YourEvent> + Send + 'static - Input type must implement
DeserializeandJsonSchema - Output event type must implement
SerializeandJsonSchema
Method Signature Rules
- Self parameter: Can be
&self,&mut self, or no self at all - Input parameter: First non-self parameter becomes the input schema
- Context parameters: Parameters named
ctxorcontextare skipped - Return type: Must be
impl Stream<Item = EventType>
Example patterns:
// No input
async
// With input
async
// With context injection
async
Additional Macros
#[derive(HandleEnum)]
Generates type-safe handle creation and parsing for activation resources.
use HandleEnum;
use Uuid;
pub const ARBOR_PLUGIN_ID: Uuid = uuid!;
This generates:
to_handle(&self) -> Handle- converts enum to Handleimpl TryFrom<&Handle>- parses Handle back to enumimpl From<EnumName> for Handle- convenience conversion
Schema Introspection
Methods generated by #[hub_methods] are automatically discoverable via Plexus RPC's schema introspection:
# Using the synapse CLI
This returns the complete schema for all methods, extracted from your Rust types.
Integration with Plexus RPC Ecosystem
This crate is part of the Plexus RPC ecosystem:
- hub-core - Core
Activationtrait andDynamicHubregistry - hub-macro - This crate - procedural macros for activations
- hub-transport - WebSocket and HTTP/SSE transport implementations
- synapse - CLI for interacting with Plexus RPC servers
- substrate - Reference Plexus RPC server implementation
Examples
See the substrate reference server for complete examples:
bash/- Shell command executionarbor/- Conversation tree storagecone/- LLM orchestration
License
MIT