Expand description
Proc macros for cruster entity definitions.
Provides #[entity] and #[entity_impl] attribute macros that generate
Entity, EntityHandler, and typed client implementations from a single
struct + impl definition.
§Stateless Entity Example
use cruster_macros::{entity, entity_impl};
#[entity]
struct UserLookup {
db: Arc<Pool<Postgres>>,
}
#[entity_impl]
impl UserLookup {
#[rpc]
async fn get_user(&self, id: String) -> Result<User, ClusterError> {
// ...
}
}§Stateful Entity Example
use cruster_macros::{entity, entity_impl};
struct CounterState { count: i32 }
#[entity]
struct Counter {}
#[entity_impl]
#[state(CounterState)]
impl Counter {
fn init(&self, _ctx: &EntityContext) -> Result<CounterState, ClusterError> {
Ok(CounterState { count: 0 })
}
// Only #[activity] methods can have &mut self
#[activity]
async fn increment(&mut self, amount: i32) -> Result<i32, ClusterError> {
self.state.count += amount;
Ok(self.state.count)
}
// &self for reads
#[rpc]
async fn get_count(&self) -> Result<i32, ClusterError> {
Ok(self.state.count)
}
}Attribute Macros§
- activity
- Marks an async method as a durable activity (external side effects).
- entity
- Attribute macro for entity struct definitions.
- entity_
impl - Attribute macro for entity impl blocks.
- entity_
trait - Attribute macro for trait capability struct definitions.
- entity_
trait_ impl - Attribute macro for trait capability impl blocks.
- method
- Marks a helper method within an entity or trait impl block.
- private
- Marks a method as private (internal only).
- protected
- Marks a method as protected (entity-to-entity only).
- public
- Marks a method as publicly accessible.
- rpc
- Marks an async method as an RPC handler (read-only operations).
- state
- Defines persistent state for an entity or entity trait.
- workflow
- Marks an async method as a durable workflow (state mutations).