ModKit Macros
This crate contains the proc-macros used by modkit.
In most crates you should import macros from modkit (it re-exports them):
use ;
If you depend on cf-modkit-macros directly, the Rust crate name is modkit_macros:
use ;
Macros
#[module(...)]
Attribute macro for declaring a ModKit module and registering it via inventory.
Parameters:
name = "..."(required)deps = ["..."](optional)capabilities = [..](optional)- Allowed values:
db,rest,rest_host,stateful,system,grpc_hub,grpc
- Allowed values:
ctor = <expr>(optional)- If omitted, the macro uses
Default::default()(so your type must implementDefault).
- If omitted, the macro uses
client = <path::to::Trait>(optional)- Current behavior: compile-time checks (object-safe +
Send + Sync + 'static) and definesMODULE_NAME. - It does not generate ClientHub registration helpers.
- Current behavior: compile-time checks (object-safe +
lifecycle(...)(optional, used forstatefulmodules)entry = "serve"(default:"serve")stop_timeout = "30s"(default:"30s"; supportsms,s,m,h)await_ready/await_ready = true|false(default:false)
Example (stateful, no ready gating):
use module;
use CancellationToken;
;
Example (stateful, with ready gating):
use module;
use CancellationToken;
;
#[lifecycle(...)]
Attribute macro applied to an impl block. It generates a modkit::lifecycle::Runnable impl and an into_module() helper.
Parameters:
method = "serve"(required)stop_timeout = "30s"(optional)await_ready/await_ready = true|false(optional)
Notes:
- If
await_readyis enabled, the runner method must accept aReadySignalas the 3rd argument.
#[grpc_client(...)]
Attribute macro applied to an empty struct. It generates a wrapper struct with:
connect(uri)andconnect_with_config(uri, cfg)usingmodkit_transport_grpc::client::connect_with_stackfrom_channel(Channel)inner_mut()- a compile-time check that the generated client type implements the API trait
Parameters:
api = "path::to::Trait"(required; string literal path)tonic = "path::to::TonicClient<Channel>"(required; string literal type)package = "..."(optional; currently unused)
Minimal example:
use grpc_client;
;
// You still implement `MyApi` manually for the generated client type.