service

Attribute Macro service 

Source
#[service]
Expand description

Attribute macro for Service impl blocks - generates message enum, Service impl, and Client methods

§Basic usage

#[service]
impl PaymentService {
    pub async fn process(&self, amount: u32) -> String {
        // ...
    }
}

§Tracing support

Use #[service(traced)] to propagate tracing spans across service calls:

#[service(traced)]
impl PaymentService {
    pub async fn process(&self, amount: u32) -> String {
        tracing::info!("Processing"); // inherits caller's span context
    }

    #[untraced]  // opt-out for this method
    pub async fn cache_refresh(&self) { ... }
}

For non-traced services, individual methods can opt-in:

#[service]
impl CleanupWorker {
    #[traced]  // opt-in just this method
    pub async fn handle_request(&self, id: u64) -> String { ... }
}

Generates:

  • Message enum with variants for each public async method
  • impl Service for PaymentService
  • Client methods struct with async methods