Struct Client
pub struct Client<S> {
raw: RawClient,
service: PhantomData<fn() -> S>,
}Expand description
Client for the QMI service S.
The client sends the requests and receives the indications of S. Use
RawClient for a service without a marker type.
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.
§Example
use std::time::Duration;
use ql_qmi::Client;
let (client, connection) = Client::<Dms>::builder().connect()?;
tokio::spawn(connection.run());
client.request(&GetRevision).await?;
client
.request(&GetRevision)
.timeout(Duration::from_secs(5))
.await?;Fields§
§raw: RawClient§service: PhantomData<fn() -> S>Implementations§
§impl<S: Service> Client<S>
impl<S: Service> Client<S>
pub const fn builder() -> ClientBuilder<S>
pub const fn builder() -> ClientBuilder<S>
Returns a builder for a client of service S.
pub fn indications<T: Indication<Service = S>>(
&self,
) -> Result<Indications<T>, Error>
pub fn indications<T: Indication<Service = S>>( &self, ) -> Result<Indications<T>, Error>
Subscribes to indications of type T.
Only indications received after this call are delivered. Subscribe before you enable indications on the service, otherwise the first ones are lost.
§Errors
Returns Error::Disconnected if the connection has stopped.
pub fn request<R: Request<Service = S>>(
&self,
request: &R,
) -> RequestBuilder<'_, R::Response>
pub fn request<R: Request<Service = S>>( &self, request: &R, ) -> RequestBuilder<'_, R::Response>
Prepares a request.
Await the returned builder to send the request. The request uses
Request::TIMEOUT if it is set, and
Request::decode_response checks the response.