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:
Error::Disconnectedif the connection has stopped.Error::TooManyRequestsif every transaction ID is in use or reserved.Error::TlvTooLargeorError::MessageTooLargeif the request doesn’t fit into a message.Error::Sendif the router rejects the request.Error::Timeoutif no response arrives in time.Error::RejectedorError::Decodeif a typed response reports a failure or can’t be decoded.
Fields§
§client: &'a RawClient§msg_id: u16§tlvs: TlvWriter§timeout: Duration§decode: fn(Message) -> Result<T, Error>§map: fn(Result<T, Error>) -> OImplementations§
§impl<'a, T> RequestBuilder<'a, T>
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>
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>
impl<T, O> RequestBuilder<'_, T, O>
pub const fn timeout(self, timeout: Duration) -> Self
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>
impl<T, O> Debug for RequestBuilder<'_, T, O>
§impl<T, O> IntoFuture for RequestBuilder<'_, T, O>
Sends the request when it is converted into a future. .await does this.
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.