pub struct PubSubHandler<T, S = Noop>where
    T: PubSubMetadata,
    S: Middleware<T>,{ /* private fields */ }
Expand description

Publish-Subscribe extension of IoHandler.

Implementations§

source§

impl<T, S> PubSubHandler<T, S>where T: PubSubMetadata, S: Middleware<T>,

source

pub fn new(handler: MetaIoHandler<T, S>) -> PubSubHandler<T, S>

Creates new PubSubHandler

source

pub fn add_subscription<F, G>( &mut self, notification: &str, subscribe: (&str, F), unsubscribe: (&str, G) )where F: SubscribeRpcMethod<T>, G: UnsubscribeRpcMethod<T>,

Adds new subscription.

Methods from Deref<Target = MetaIoHandler<T, S>>§

source

pub fn add_alias(&mut self, alias: &str, other: &str)

Adds an alias to a method.

source

pub fn add_sync_method<F>(&mut self, name: &str, method: F)where F: RpcMethodSync,

Adds new supported synchronous method.

A backward-compatible wrapper.

source

pub fn add_method<F>(&mut self, name: &str, method: F)where F: RpcMethodSimple,

Adds new supported asynchronous method.

source

pub fn add_notification<F>(&mut self, name: &str, notification: F)where F: RpcNotificationSimple,

Adds new supported notification

source

pub fn add_method_with_meta<F>(&mut self, name: &str, method: F)where F: RpcMethod<T>,

Adds new supported asynchronous method with metadata support.

source

pub fn add_notification_with_meta<F>(&mut self, name: &str, notification: F)where F: RpcNotification<T>,

Adds new supported notification with metadata support.

source

pub fn extend_with<F>(&mut self, methods: F)where F: IntoIterator<Item = (String, RemoteProcedure<T>)>,

Extend this MetaIoHandler with methods defined elsewhere.

source

pub fn handle_request_sync(&self, request: &str, meta: T) -> Option<String>

Handle given request synchronously - will block until response is available. If you have any asynchronous methods in your RPC it is much wiser to use handle_request instead and deal with asynchronous requests in a non-blocking fashion.

source

pub fn handle_request( &self, request: &str, meta: T ) -> Map<Either<Ready<Option<Response>>, Either<<S as Middleware<T>>::Future, Either<Map<Either<<S as Middleware<T>>::CallFuture, Either<Pin<Box<dyn Future<Output = Option<Output>> + Send + 'static, Global>>, Ready<Option<Output>>>>, fn(_: Option<Output>) -> Option<Response>>, Map<JoinAll<Either<<S as Middleware<T>>::CallFuture, Either<Pin<Box<dyn Future<Output = Option<Output>> + Send + 'static, Global>>, Ready<Option<Output>>>>>, fn(_: Vec<Option<Output>, Global>) -> Option<Response>>>>>, fn(_: Option<Response>) -> Option<String>>

Handle given request asynchronously.

source

pub fn handle_rpc_request( &self, request: Request, meta: T ) -> Either<<S as Middleware<T>>::Future, Either<Map<Either<<S as Middleware<T>>::CallFuture, Either<Pin<Box<dyn Future<Output = Option<Output>> + Send + 'static, Global>>, Ready<Option<Output>>>>, fn(_: Option<Output>) -> Option<Response>>, Map<JoinAll<Either<<S as Middleware<T>>::CallFuture, Either<Pin<Box<dyn Future<Output = Option<Output>> + Send + 'static, Global>>, Ready<Option<Output>>>>>, fn(_: Vec<Option<Output>, Global>) -> Option<Response>>>>

Handle deserialized RPC request.

source

pub fn handle_call( &self, call: Call, meta: T ) -> Either<<S as Middleware<T>>::CallFuture, Either<Pin<Box<dyn Future<Output = Option<Output>> + Send + 'static, Global>>, Ready<Option<Output>>>>

Handle single call asynchronously.

source

pub fn iter(&self) -> impl Iterator<Item = (&String, &RemoteProcedure<T>)>

Returns an iterator visiting all methods in arbitrary order.

Trait Implementations§

source§

impl<T> Default for PubSubHandler<T, Noop>where T: PubSubMetadata,

source§

fn default() -> PubSubHandler<T, Noop>

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

impl<T, S> Deref for PubSubHandler<T, S>where T: PubSubMetadata, S: Middleware<T>,

§

type Target = MetaIoHandler<T, S>

The resulting type after dereferencing.
source§

fn deref(&self) -> &<PubSubHandler<T, S> as Deref>::Target

Dereferences the value.
source§

impl<T, S> DerefMut for PubSubHandler<T, S>where T: PubSubMetadata, S: Middleware<T>,

source§

fn deref_mut(&mut self) -> &mut <PubSubHandler<T, S> as Deref>::Target

Mutably dereferences the value.
source§

impl<M> Handler for PubSubHandler<M>where M: PubSubMetadata + Unpin + Debug + From<Arc<Session>>,

§

type Metadata = M

The type to use as the metadata for the IO handler. Especially relevant for PubSub.
source§

fn add_method<F>(&mut self, name: &str, method: F)where F: RpcMethodSimple,

Add a JSON-RPC method.
source§

fn add_subscription<F, G>( &mut self, notification: &str, subscribe: (&str, F), unsubscribe: (&str, G) )where F: SubscribeRpcMethod<M>, G: UnsubscribeRpcMethod<M>,

Add a JSON-RPC subscription.
source§

fn as_meta_io_handler(&self) -> MetaIoHandler<Self::Metadata>

Cast this down to an instance of MetaIoHandler.
source§

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

Get a list of all the supported JSON-RPC methods.
source§

fn handle_request_sync( &self, request: &str, meta: Self::Metadata ) -> Option<String>

Programmatically trigger the handling of a JSON-RPC message. TODO: support async
source§

fn metadata_from_sender(sender: UnboundedSender<String>) -> Self::Metadata

Derive an instance of the Self::Metadata associated type from an UnboundedSender.
source§

fn new() -> Self

Create a new instance of a Handler implementation.
source§

impl<T, S> Into<MetaIoHandler<T, S>> for PubSubHandler<T, S>where T: PubSubMetadata, S: Middleware<T>,

source§

fn into(self) -> MetaIoHandler<T, S>

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl<T, S = Noop> !RefUnwindSafe for PubSubHandler<T, S>

§

impl<T, S> Send for PubSubHandler<T, S>

§

impl<T, S> Sync for PubSubHandler<T, S>

§

impl<T, S> Unpin for PubSubHandler<T, S>where S: Unpin,

§

impl<T, S = Noop> !UnwindSafe for PubSubHandler<T, S>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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