Skip to main content

RequestBuilder

Struct RequestBuilder 

pub struct RequestBuilder<'a, T, O = Result<T, Error>> {
    client: &'a RawClient,
    msg_id: u16,
    tlvs: TlvWriter,
    timeout: Duration,
    decode: fn(Message) -> Result<T, Error>,
    map: fn(Result<T, Error>) -> O,
}
Expand description

A request that is ready to be sent.

Returned by Client::request and RawClient::raw_request. Await it to send the request and wait for the response. T is the decoded response and O the output, which RequestBuilder::map can change.

§Errors

Awaiting the request returns these errors:

Fields§

§client: &'a RawClient§msg_id: u16§tlvs: TlvWriter§timeout: Duration§decode: fn(Message) -> Result<T, Error>§map: fn(Result<T, Error>) -> O

Implementations§

§

impl<'a, T> RequestBuilder<'a, T>

pub(super) const fn new( client: &'a RawClient, msg_id: u16, tlvs: TlvWriter, decode: fn(Message) -> Result<T, Error>, ) -> Self

pub fn map<O>(self, map: fn(Result<T, Error>) -> O) -> RequestBuilder<'a, T, O>

Maps the result of the request to another output.

map gets the decoded response or the error. A service crate uses it to return its own types and errors.

§Example
use ql_qmi::status::QmiError;
use ql_qmi::{Error, RequestBuilder};

/// Returns `true` if the call was stopped, or `false` if there was none.
fn stop_network(client: &Client<Wds>) -> RequestBuilder<'_, (), Result<bool, Error>> {
    client.request(&StopNetwork).map(|result| match result {
        Ok(()) => Ok(true),
        Err(Error::Rejected {
            error: QmiError::NO_EFFECT,
            ..
        }) => Ok(false),
        Err(err) => Err(err),
    })
}
§

impl<T, O> RequestBuilder<'_, T, O>

pub const fn timeout(self, timeout: Duration) -> Self

Overrides the default timeout for this request.

The default is Request::TIMEOUT or the timeout of the client.

Trait Implementations§

§

impl<T, O> Debug for RequestBuilder<'_, T, O>

§

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

Formats the value using the given formatter. Read more
§

impl<T, O> IntoFuture for RequestBuilder<'_, T, O>

Sends the request when it is converted into a future. .await does this.

The conversion needs a tokio runtime with the time driver enabled. The timeout starts at this point. Dropping the future abandons the request. The service may still carry it out, but the response is discarded.

§

type IntoFuture = ResponseFuture<T, O>

Which kind of future are we turning this into?
§

type Output = O

The output that the future will produce on completion.
§

fn into_future(self) -> ResponseFuture<T, O> ⓘ

Creates a future from a value. Read more

Auto Trait Implementations§

§

impl<'a, T, O> Freeze for RequestBuilder<'a, T, O>
where fn(Message) -> Result<T, Error>: Freeze, fn(Result<T, Error>) -> O: Freeze,

§

impl<'a, T, O> RefUnwindSafe for RequestBuilder<'a, T, O>

§

impl<'a, T, O> Send for RequestBuilder<'a, T, O>
where fn(Message) -> Result<T, Error>: Send, fn(Result<T, Error>) -> O: Send,

§

impl<'a, T, O> Sync for RequestBuilder<'a, T, O>
where fn(Message) -> Result<T, Error>: Sync, fn(Result<T, Error>) -> O: Sync,

§

impl<'a, T, O> Unpin for RequestBuilder<'a, T, O>
where fn(Message) -> Result<T, Error>: Unpin, fn(Result<T, Error>) -> O: Unpin,

§

impl<'a, T, O> UnsafeUnpin for RequestBuilder<'a, T, O>

§

impl<'a, T, O> UnwindSafe for RequestBuilder<'a, T, O>
where fn(Message) -> Result<T, Error>: UnwindSafe, fn(Result<T, Error>) -> O: UnwindSafe,

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more