pub struct ResponseRouter<T: JsonRpcResponse = Value> { /* 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.
Implementations§
Source§impl ResponseRouter<Value>
impl ResponseRouter<Value>
Sourcepub fn cast<T: JsonRpcResponse>(self) -> ResponseRouter<T>
pub fn cast<T: JsonRpcResponse>(self) -> ResponseRouter<T>
Cast this response context to a different response type.
The provided type T will be serialized to JSON before sending.
Source§impl<T: JsonRpcResponse> ResponseRouter<T>
impl<T: JsonRpcResponse> ResponseRouter<T>
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>
pub fn erase_to_json(self) -> ResponseRouter<Value>
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 respond_with_result(
self,
response: Result<T, Error>,
) -> Result<(), Error>
pub fn respond_with_result( self, response: Result<T, Error>, ) -> Result<(), Error>
Complete the response by sending the result to the waiting task.
Sourcepub fn respond(self, response: T) -> Result<(), Error>
pub fn respond(self, response: T) -> Result<(), Error>
Complete the response by sending a value to the waiting task.