Skip to main content

RawClient

Struct RawClient 

pub struct RawClient {
    requests: UnboundedSender<Outgoing>,
    indications: WeakSender<Message>,
    timeout: Duration,
}
Expand description

Untyped client for one QMI service.

It sends requests from raw TLVs and returns the responses without checking them. Use it for a service that has no marker type. A Client adds types on top.

The client prepares requests. Its Connection sends them and receives the responses and indications, so it must run for requests to complete. Requests can run concurrently. Cloning the client is cheap. Dropping every clone stops the connection.

Error::TooManyRequests only limits the requests in flight. Requests that wait for the connection to run are queued in memory without a limit.

§Example

use std::time::Duration;

use ql_qmi::RawClient;
use ql_qmi::codec::TlvWriter;

let (client, connection) = RawClient::builder(0x401, 1).connect()?;
tokio::spawn(connection.run());
let response = client
    .raw_request(0x507, TlvWriter::new())
    .timeout(Duration::from_secs(5))
    .await?;
println!("{response:?}");

Fields§

§requests: UnboundedSender<Outgoing>§indications: WeakSender<Message>

Weak, so that subscribers see the channel close once the connection stops.

§timeout: Duration

Implementations§

§

impl RawClient

pub const fn builder(service: u32, version: u8) -> RawClientBuilder

Returns a builder for a client of a QMI service.

version is the IDL major version of the service.

pub(super) const fn new( requests: UnboundedSender<Outgoing>, indications: WeakSender<Message>, timeout: Duration, ) -> Self

pub fn raw_indications(&self) -> Result<Receiver<Message>, Error>

Subscribes to every indication, without filtering or decoding them.

Only indications received after this call are delivered. The receiver closes when the connection stops.

§Example
use ql_qmi::RawClient;
use tokio::sync::broadcast::error::RecvError;

let (client, connection) = RawClient::builder(0x401, 1).connect()?;
tokio::spawn(connection.run());
let mut indications = client.raw_indications()?;
loop {
    match indications.recv().await {
        Ok(indication) => println!("{:#06x}: {indication:?}", indication.msg_id()),
        Err(RecvError::Lagged(missed)) => eprintln!("missed {missed} indications"),
        Err(RecvError::Closed) => break,
    }
}
§Errors

Returns Error::Disconnected if the connection has stopped.

pub fn raw_request( &self, msg_id: u16, tlvs: TlvWriter, ) -> RequestBuilder<'_, Message>

Prepares a request from raw TLVs.

Await the returned builder to send the request. The response is returned as is, even if its status reports a failure.

pub(super) fn send( &self, msg_id: u16, tlvs: TlvWriter, timeout: Duration, ) -> Receiver<Result<Message, Error>> ⓘ

Hands a request to the connection.

The returned receiver gets the response, or the error if the request can’t be sent.

pub(super) const fn timeout(&self) -> Duration

Trait Implementations§

§

impl Clone for RawClient

§

fn clone(&self) -> RawClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for RawClient

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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