Skip to main content

MethodRegistry

Struct MethodRegistry 

Source
pub struct MethodRegistry { /* private fields */ }
Expand description

Method registry with optional authentication

Implementations§

Source§

impl MethodRegistry

Source

pub fn new(methods: Vec<Box<dyn JsonRPCMethod>>) -> Self

Create a new method registry with the given method implementations

Source

pub fn empty() -> Self

Create an empty registry

Source

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());
Source

pub fn add_method(self, method: Box<dyn JsonRPCMethod>) -> Self

Add a method implementation to the registry

Source

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

Source

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.

Source

pub fn has_method(&self, method_name: &str) -> bool

Check if a method is registered

Source

pub fn get_methods(&self) -> Vec<String>

Get list of all registered methods

Source

pub fn method_count(&self) -> usize

Get the number of registered methods

Source

pub fn generate_openapi_spec(&self, title: &str, version: &str) -> OpenApiSpec

Generate OpenAPI specification for all registered methods

Source

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

Source

pub fn export_openapi_json( &self, title: &str, version: &str, ) -> Result<String, Error>

Export OpenAPI spec as JSON string

Trait Implementations§

Source§

impl Default for MethodRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Handler for MethodRegistry

Source§

fn handle_request<'life0, 'async_trait>( &'life0 self, request: Request, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a JSON-RPC request and return a response
Source§

fn handle_notification<'life0, 'async_trait>( &'life0 self, notification: Notification, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a JSON-RPC notification (no response expected)
Source§

fn supports_method(&self, method: &str) -> bool

Check if a method is supported
Source§

fn get_supported_methods(&self) -> Vec<String>

Get list of supported methods
Source§

impl MessageProcessor for MethodRegistry

Source§

fn process_message<'life0, 'async_trait>( &'life0 self, message: Message, ) -> Pin<Box<dyn Future<Output = Option<Response>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Process a single JSON-RPC message
Source§

fn process_batch<'life0, 'async_trait>( &'life0 self, messages: Vec<Message>, ) -> Pin<Box<dyn Future<Output = Vec<Response>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Process a batch of JSON-RPC messages
Source§

fn get_capabilities(&self) -> ProcessorCapabilities

Get processor capabilities
Source§

fn supports_batching(&self) -> bool

Check if batch processing is supported

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more