rapace_introspection/
lib.rs

1#![doc = include_str!("../README.md")]
2
3// Re-export types from rapace-registry for convenience
4pub use rapace_registry::introspection::{
5    ArgInfo, DefaultServiceIntrospection, MethodInfo, ServiceInfo,
6};
7
8/// Service introspection RPC interface.
9///
10/// This service allows clients to query what services and methods are registered
11/// in the global service registry.
12#[rapace::service]
13pub trait ServiceIntrospection {
14    /// List all services registered in this process.
15    ///
16    /// Returns a snapshot of all currently registered services and their methods.
17    async fn list_services(&self) -> Vec<ServiceInfo>;
18
19    /// Describe a specific service by name.
20    ///
21    /// Returns detailed information about the service if it exists, `None` otherwise.
22    async fn describe_service(&self, name: String) -> Option<ServiceInfo>;
23
24    /// Check if a method ID is supported.
25    ///
26    /// Returns `true` if any registered service has a method with this ID.
27    async fn has_method(&self, method_id: u32) -> bool;
28}
29
30impl ServiceIntrospection for DefaultServiceIntrospection {
31    async fn list_services(&self) -> Vec<ServiceInfo> {
32        self.list_services()
33    }
34
35    async fn describe_service(&self, name: String) -> Option<ServiceInfo> {
36        self.describe_service(&name)
37    }
38
39    async fn has_method(&self, method_id: u32) -> bool {
40        self.has_method(method_id)
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[tokio::test]
49    async fn test_introspection_impl() {
50        let introspection = DefaultServiceIntrospection::new();
51
52        // Should work without errors (calling inherent methods, not async trait methods)
53        let _services = introspection.list_services();
54        let _has_zero = introspection.has_method(0);
55        let _describe = introspection.describe_service("NonExistent");
56    }
57}