guest-macro
Procedural macros for generating WebAssembly guest infrastructure.
Overview
This crate provides the guest! macro that generates the necessary guest infrastructure for WebAssembly components with WASI capabilities. Instead of manually implementing HTTP handlers and messaging consumers, you declaratively specify your routes and topics.
Usage
Add guest-macro to your dependencies:
[]
= { = true }
Then use the guest! macro to generate your guest infrastructure:
use guest;
guest!;
Configuration Format
The macro accepts a struct-like syntax with the following fields:
Required Fields
owner: A string literal identifying the owner/organizationprovider: An identifier for the provider type that implements the necessary traits
Optional Fields
http: An array of HTTP route definitionsmessaging: An array of messaging topic definitions
HTTP Routes
HTTP routes are defined with the syntax:
"/path": method
Supported Methods
get(Request, Response)- GET request handlerpost(Request, Response)- POST request handler
Request Modifiers
with_query- For GET requests, indicates the request type should be populated from query parameterswith_body- For POST requests, indicates the request should include the raw body bytes
Path Parameters
Path parameters use curly brace syntax and are automatically extracted:
"/users/{user_id}/posts/{post_id}": get
Messaging Topics
Messaging topics are defined with the syntax:
"topic-name.version": MessageType
The macro generates handlers that match incoming messages by topic name.
Generated Code
The macro generates the following modules under #[cfg(target_arch = "wasm32")]:
HTTP Module (mod http)
- Implements
wasip3::exports::http::handler::Guesttrait - Sets up an Axum router with all defined routes
- Generates async handler functions for each route with OpenTelemetry instrumentation
Messaging Module (mod messaging)
- Implements
wasi_messaging::incoming_handler::Guesttrait - Routes incoming messages to appropriate handlers based on topic
- Generates async processor functions with OpenTelemetry instrumentation
Example
use guest;
// Define your provider
;
// Generate guest infrastructure
guest!;
License
MIT OR Apache-2.0