pub struct MethodRegistry { /* private fields */ }Expand description
Method registry with optional authentication
Implementations§
Source§impl MethodRegistry
impl MethodRegistry
Sourcepub fn new(methods: Vec<Box<dyn JsonRPCMethod>>) -> Self
pub fn new(methods: Vec<Box<dyn JsonRPCMethod>>) -> Self
Create a new method registry with the given method implementations
Sourcepub fn with_auth<A: AuthPolicy + 'static>(self, policy: A) -> Self
pub fn with_auth<A: AuthPolicy + 'static>(self, policy: A) -> Self
Set an authentication/authorization policy
When set, can_access will be checked before executing methods.
The user implements ALL auth logic in the trait.
§Example
let registry = MethodRegistry::new(methods)
.with_auth(MyAuthPolicy::new());Sourcepub fn add_method(self, method: Box<dyn JsonRPCMethod>) -> Self
pub fn add_method(self, method: Box<dyn JsonRPCMethod>) -> Self
Add a method implementation to the registry
Sourcepub async fn call(
&self,
method_name: &str,
params: Option<Value>,
id: Option<RequestId>,
) -> Response
pub async fn call( &self, method_name: &str, params: Option<Value>, id: Option<RequestId>, ) -> Response
Call a registered method asynchronously using compile-time dispatch Note: This method should typically be replaced by using the dispatch_methods! macro directly for better compile-time optimization
Sourcepub async fn call_with_context(
&self,
method_name: &str,
params: Option<Value>,
id: Option<RequestId>,
ctx: &ConnectionContext,
) -> Response
pub async fn call_with_context( &self, method_name: &str, params: Option<Value>, id: Option<RequestId>, ctx: &ConnectionContext, ) -> Response
Call a registered method with authentication context
Use this when you have connection context from your transport layer.
Sourcepub fn has_method(&self, method_name: &str) -> bool
pub fn has_method(&self, method_name: &str) -> bool
Check if a method is registered
Sourcepub fn get_methods(&self) -> Vec<String>
pub fn get_methods(&self) -> Vec<String>
Get list of all registered methods
Sourcepub fn method_count(&self) -> usize
pub fn method_count(&self) -> usize
Get the number of registered methods
Sourcepub fn generate_openapi_spec(&self, title: &str, version: &str) -> OpenApiSpec
pub fn generate_openapi_spec(&self, title: &str, version: &str) -> OpenApiSpec
Generate OpenAPI specification for all registered methods
Sourcepub fn generate_openapi_spec_with_info(
&self,
title: &str,
version: &str,
description: Option<&str>,
servers: Vec<OpenApiServer>,
) -> OpenApiSpec
pub fn generate_openapi_spec_with_info( &self, title: &str, version: &str, description: Option<&str>, servers: Vec<OpenApiServer>, ) -> OpenApiSpec
Generate OpenAPI specification with custom info and servers