Skip to main content

ResponseRouter

Struct ResponseRouter 

Source
pub struct ResponseRouter<T: JsonRpcResponse = Value, P: Protocol = Raw> { /* private fields */ }
Expand description

Context for handling an incoming JSON-RPC response.

This is the response-side counterpart to Responder. While Responder handles incoming requests (where you send a response over the wire), ResponseRouter handles incoming responses (where you route the response to a local task waiting for it).

Both are fundamentally “sinks” that push the message through a send_fn, but they represent different points in the message lifecycle and carry different metadata.

§Drop Behavior

Dropping a ResponseRouter without routing the response (for example, from a dispatch handler that claims a Dispatch::Response) discards the response: the local awaiter observes the response as never received. The request still counts as settled: routing a response this far disarms the originating SentRequest’s drop-time auto-cancellation even if the router is never invoked, since the peer has already answered.

P is the Protocol marker that types id; see Responder.

Implementations§

Source§

impl<P: Protocol> ResponseRouter<Value, P>

Source

pub fn cast<T: JsonRpcResponse>(self) -> ResponseRouter<T, P>

Cast this response context to a different response type.

The provided type T will be serialized to JSON before sending.

Source§

impl<T: JsonRpcResponse, P: Protocol> ResponseRouter<T, P>

Source

pub fn method(&self) -> &str

Method of the original request

Source

pub fn id(&self) -> &P::RequestId

ID of the original request, as this router’s protocol version types it.

Source

pub fn raw_id(&self) -> &RawJsonRpcId

ID of the original request exactly as it was sent on the wire.

This is the same ID as id, in the version-neutral form used by routers, forwarders and tracing.

Source

pub fn role_id(&self) -> RoleId

The peer to which the original request was sent.

This is the peer from which we expect to receive the response.

Source

pub fn erase_to_json(self) -> ResponseRouter<Value, P>

Convert to a ResponseRouter that expects a JSON value and which checks (dynamically) that the JSON value it receives can be converted to T.

Source

pub fn into_raw(self) -> ResponseRouter<T, Raw>

The same router with a version-neutral Raw request ID. This never fails.

Source

pub fn route_with_result(self, response: Result<T, Error>) -> Result<(), Error>

Route the response result to the waiting task.

Source

pub fn route(self, response: T) -> Result<(), Error>

Route a successful response value to the waiting task.

Source

pub fn route_with_internal_error( self, message: impl ToString, ) -> Result<(), Error>

Route an internal error to the waiting task.

Source

pub fn route_with_error(self, error: Error) -> Result<(), Error>

Route an error response to the waiting task.

Source§

impl<T: JsonRpcResponse> ResponseRouter<T, Raw>

Source

pub fn into_protocol<Q: Protocol>(self) -> Result<ResponseRouter<T, Q>, Error>

Convert this version-neutral router to protocol Q’s router.

Only the request ID’s type changes. The SDK never assigns null to requests it sends, so this succeeds for every marker.

Trait Implementations§

Source§

impl<T: JsonRpcResponse, P: Protocol> Debug for ResponseRouter<T, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T = Value, P = Raw> !RefUnwindSafe for ResponseRouter<T, P>

§

impl<T = Value, P = Raw> !Sync for ResponseRouter<T, P>

§

impl<T = Value, P = Raw> !UnwindSafe for ResponseRouter<T, P>

§

impl<T, P> Freeze for ResponseRouter<T, P>
where HandleId<P>: Freeze, Box<dyn FnOnce(Result<T, Error>) -> Result<(), Error> + Send>: Freeze,

§

impl<T, P> Send for ResponseRouter<T, P>
where HandleId<P>: Send, Box<dyn FnOnce(Result<T, Error>) -> Result<(), Error> + Send>: Send,

§

impl<T, P> Unpin for ResponseRouter<T, P>
where HandleId<P>: Unpin, Box<dyn FnOnce(Result<T, Error>) -> Result<(), Error> + Send>: Unpin,

§

impl<T, P> UnsafeUnpin for ResponseRouter<T, P>
where HandleId<P>: UnsafeUnpin, Box<dyn FnOnce(Result<T, Error>) -> Result<(), Error> + Send>: UnsafeUnpin,

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> IntoMaybeUndefined<T> for T

Source§

fn into_maybe_undefined(self) -> MaybeUndefined<T>

Converts this value into a three-state builder argument.
Source§

impl<T> IntoOption<T> for T

Source§

fn into_option(self) -> Option<T>

Converts this value into an optional builder argument.
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