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.
Implementations§
Source§impl<P: Protocol> ResponseRouter<Value, P>
impl<P: Protocol> ResponseRouter<Value, P>
Sourcepub fn cast<T: JsonRpcResponse>(self) -> ResponseRouter<T, P>
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>
impl<T: JsonRpcResponse, P: Protocol> ResponseRouter<T, P>
Sourcepub fn id(&self) -> &P::RequestId
pub fn id(&self) -> &P::RequestId
ID of the original request, as this router’s protocol version types it.
Sourcepub fn raw_id(&self) -> &RawJsonRpcId
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.
Sourcepub fn role_id(&self) -> RoleId
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.
Sourcepub fn erase_to_json(self) -> ResponseRouter<Value, P>
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.
Sourcepub fn into_raw(self) -> ResponseRouter<T, Raw>
pub fn into_raw(self) -> ResponseRouter<T, Raw>
The same router with a version-neutral Raw request ID. This never
fails.
Sourcepub fn route_with_result(self, response: Result<T, Error>) -> Result<(), Error>
pub fn route_with_result(self, response: Result<T, Error>) -> Result<(), Error>
Route the response result to the waiting task.
Sourcepub fn route(self, response: T) -> Result<(), Error>
pub fn route(self, response: T) -> Result<(), Error>
Route a successful response value to the waiting task.
Source§impl<T: JsonRpcResponse> ResponseRouter<T, Raw>
impl<T: JsonRpcResponse> ResponseRouter<T, Raw>
Sourcepub fn into_protocol<Q: Protocol>(self) -> Result<ResponseRouter<T, Q>, Error>
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.