Skip to main content

RpcRouter

Struct RpcRouter 

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

Thread-safe registry mapping JSON-RPC method names to async handlers with zero-allocation lookup.

Implementations§

Source§

impl RpcRouter

Inherent implementation of RpcRouter.

Source

pub fn new() -> Self

Creates an empty RpcRouter.

§Returns
  • Self - Empty router.
Source

pub fn add_interceptor( &mut self, interceptor: Arc<dyn RpcInterceptor>, ) -> &mut Self

Registers an extensible RpcInterceptor invoked before every method dispatch.

§Arguments
  • Arc<dyn RpcInterceptor> - Interceptor implementation.
§Returns
  • &mut Self - This router for fluent chaining.
Source

pub fn register<N, F, Fut>(&mut self, name: N, handler: F) -> &mut Self
where N: Into<String>, F: Fn(Option<Value>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value, RpcError>> + Send + 'static,

Registers an async method handler under name.

§Arguments
  • N - Method name convertible into String.
  • F - Async callback accepting Option<Value> and returning Fut.
§Returns
  • &mut Self - This router for fluent chaining.
Source

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

Reports whether name is registered on this router.

§Arguments
  • &str - Method name to check.
§Returns
  • bool - true when registered.
Source

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

Returns a list of all registered method names.

§Returns
  • Vec<String> - Registered method names.
Source

pub async fn dispatch_value(&self, raw: Value) -> Option<RpcResponse>

Dispatches one parsed JSON value representing a single JSON-RPC 2.0 call or notification.

§Arguments
  • Value - Raw JSON object value.
§Returns
  • Option<RpcResponse> - None for valid notifications, otherwise the response envelope.
Source

pub async fn dispatch_bytes( &self, raw: &[u8], config: &RpcConfig, ) -> Option<Vec<u8>>

Parses and dispatches raw JSON-RPC 2.0 request bytes (single call, notification, or concurrent batch).

§Arguments
  • &[u8] - Raw HTTP request payload bytes.
  • &RpcConfig - Batch and payload safety bounds.
§Returns
  • Option<Vec<u8>> - Serialized JSON response bytes, or None when every call was a notification.

Trait Implementations§

Source§

impl Clone for RpcRouter

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for RpcRouter

Default construction for RpcRouter.

Source§

fn default() -> Self

Constructs an empty RpcRouter.

Auto Trait Implementations§

§

impl !RefUnwindSafe for RpcRouter

§

impl !UnwindSafe for RpcRouter

§

impl Forget for RpcRouter

§

impl Freeze for RpcRouter
where PhantomData<fn() -> FxHasher>: Freeze, *const u8 is !null: Freeze, PhantomData<(String, Arc<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = Result<Value, RpcError>> + Send>> + Sync + Send>)>: Freeze, PhantomData<Arc<dyn RpcInterceptor>>: Freeze,

§

impl Move for RpcRouter

§

impl Send for RpcRouter
where RawTable<(String, Arc<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = Result<Value, RpcError>> + Send>> + Sync + Send>)>: Send, RawVecInner: Send, Arc<dyn RpcInterceptor>: Send,

§

impl Sync for RpcRouter
where RawTable<(String, Arc<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = Result<Value, RpcError>> + Send>> + Sync + Send>)>: Sync, RawVecInner: Sync, Arc<dyn RpcInterceptor>: Sync,

§

impl Unpin for RpcRouter
where *const u8 is !null: Unpin, Arc<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = Result<Value, RpcError>> + Send>> + Sync + Send>: Unpin, Arc<dyn RpcInterceptor>: Unpin,

§

impl UnsafeUnpin for RpcRouter

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> AnySend for T
where T: Any + Send,

Source§

impl<T> AnySendClone for T
where T: Any + Send + Clone,

Source§

impl<T> AnySendSync for T
where T: Any + Send + Sync,

Source§

impl<T> AnySendSyncClone for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> AnySync for T
where T: Any + Sync,

Source§

impl<T> AnySyncClone for T
where T: Any + Sync + Clone,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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