Skip to main content

ModuleService

Trait ModuleService 

Source
pub trait ModuleService: Send + Sync {
    // Required methods
    fn service_id(&self) -> &'static str;
    fn service_type(&self) -> &'static str;
    fn module_name(&self) -> &'static str;
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<ServiceHealth, String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn as_any(&self) -> Option<&dyn Any> { ... }
}
Expand description

Trait for module services that can be registered and discovered

Services implement this trait to be registered in the ServiceRegistry. The registry provides service discovery and health checking.

§Example

ⓘ
use backbone_core::registry::ModuleService;

struct UserQueryService { /* ... */ }

#[async_trait]
impl ModuleService for UserQueryService {
    fn service_id(&self) -> &'static str {
        "sapiens.user_query"
    }

    fn service_type(&self) -> &'static str {
        "query"
    }

    fn module_name(&self) -> &'static str {
        "sapiens"
    }

    async fn health_check(&self) -> Result<ServiceHealth, String> {
        Ok(ServiceHealth::healthy())
    }
}

Required Methods§

Source

fn service_id(&self) -> &'static str

Unique service identifier (e.g., “sapiens.user_query”, “postman.email_sender”)

Format: {module}.{service_name}

Source

fn service_type(&self) -> &'static str

Service type (e.g., “query”, “command”, “notification”)

Source

fn module_name(&self) -> &'static str

Module that owns this service (e.g., “sapiens”, “postman”)

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<ServiceHealth, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Health check for the service

Provided Methods§

Source

fn as_any(&self) -> Option<&dyn Any>

Optional: Get the service as Any for downcasting

Override this to enable type-safe service retrieval via get_typed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§