Skip to main content

PreparedRequest

Struct PreparedRequest 

Source
pub struct PreparedRequest<T> { /* private fields */ }
Expand description

A request that has not been published to its connection.

Created by ConnectionTo::prepare_request or ConnectionTo::prepare_request_to. Preparation serializes the request but does not register a pending reply or enqueue outgoing traffic. Dropping this value sends neither the request nor a cancellation notification.

A consuming method publishes the request synchronously:

  • on_receiving_result, on_receiving_ok_result, and forward_response_to register ordered response handling before publication. When a peer response is routed during its original dispatch, later inbound messages wait for that handling to finish.
  • block_task publishes immediately and returns an unordered response future. Publication does not wait for its first poll.
  • detach publishes immediately and discards the response.

Ordered callbacks must do bounded work and must not await later inbound traffic on the same connection. EOF failures and responses routed through a retained ResponseRouter after their original dispatch have no ordering barrier. See crate::concepts::ordering.

§Errors

Preparation and publication failures are delivered to the selected response consumer. Callback-style methods return an error if their task cannot be registered; in that case the request is not published. detach returns preparation or publication errors directly because it has no response consumer. A callback returning an error terminates the connection.

Implementations§

Source§

impl<T> PreparedRequest<T>

Source

pub fn id(&self) -> &RequestId

The ID reserved for this request, which has not been sent yet.

Source

pub fn method(&self) -> &str

The method of the prepared request.

Source

pub fn map<U>( self, map_fn: impl FnOnce(T) -> Result<U, Error> + 'static + Send, ) -> PreparedRequest<U>
where T: 'static,

Map a successful response without publishing the request.

The mapper has the same contract as SentRequest::map.

Source

pub fn forward_cancellation_from(self, source: RequestCancellation) -> Self

Register a cancellation source without publishing the request.

After publication, cancellation is forwarded while awaiting the response, as described by SentRequest::forward_cancellation_from.

Source

pub fn block_task(self) -> impl Future<Output = Result<T, Error>>

Publish now and return an unordered future for the response.

The request is enqueued during this call, not when the future is first polled. Dropping that future asks the peer to cancel a still-outstanding request. Await it only outside the dispatch loop; awaiting it in an incoming handler deadlocks just like SentRequest::block_task.

§Errors

The returned future delivers preparation, publication, and response errors.

Source

pub fn detach(self) -> Result<(), Error>

Publish now and discard the eventual response without cancelling.

§Errors

Returns immediate preparation or enqueue failures. Later local transformation errors and peer response errors are discarded along with successful responses. Transport failures still propagate through the connection future.

Source

pub fn on_receiving_result<F>( self, task: impl FnOnce(Result<T, Error>) -> F + 'static + Send, ) -> Result<(), Error>
where T: 'static, F: Future<Output = Result<(), Error>> + 'static + Send,

Register an ordered callback, then publish the request.

Ordering is selected before publication, even when the connection runs concurrently. See PreparedRequest for barrier limits and deadlock risks.

§Errors

Returns an error if the callback task cannot be registered, without publishing the request. Preparation and publication errors are delivered to the callback. Returning an error from the callback ends the connection.

Source

pub fn on_receiving_ok_result<F>( self, responder: Responder<T>, task: impl FnOnce(T, Responder<T>) -> F + 'static + Send, ) -> Result<(), Error>
where T: JsonRpcResponse, F: Future<Output = Result<(), Error>> + 'static + Send,

Register an ordered success callback, then publish the request.

Errors are forwarded to responder, as with SentRequest::on_receiving_ok_result.

§Errors

Returns a task-registration error without publishing the request. Preparation, publication, and response errors are forwarded to responder. Returning an error from the callback ends the connection.

Source

pub fn forward_response_to(self, responder: Responder<T>) -> Result<(), Error>
where T: JsonRpcResponse,

Register ordered response forwarding, then publish the request.

Cancellation and response errors propagate as with SentRequest::forward_response_to.

§Errors

Returns a task-registration error without publishing the request. Preparation, publication, and response errors are forwarded to responder.

Trait Implementations§

Source§

impl<T: Debug> Debug for PreparedRequest<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for PreparedRequest<T>

§

impl<T> !Sync for PreparedRequest<T>

§

impl<T> !UnwindSafe for PreparedRequest<T>

§

impl<T> Freeze for PreparedRequest<T>
where SentRequest<T>: Freeze,

§

impl<T> Send for PreparedRequest<T>
where SentRequest<T>: Send,

§

impl<T> Unpin for PreparedRequest<T>
where SentRequest<T>: Unpin,

§

impl<T> UnsafeUnpin for PreparedRequest<T>

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