Trait Request
pub trait Request {
type Response: for<'a> TryFrom<&'a Message, Error = DecodeError>;
type Service: Service;
const ID: u16;
const TIMEOUT: Option<Duration> = None;
// Required method
fn encode(&self, tlvs: &mut TlvWriter);
// Provided method
fn decode_response(response: Message) -> Result<Self::Response, Error> { ... }
}Expand description
A request to a QMI service.
Send it with Client::request. By default, the
response contains the result in TLV 0x02, see Status. Override
decode_response for a response without it.
§Example
use ql_qmi::codec::{DecodeError, Request, TlvWriter, Utf8Bytes};
use ql_qmi::{Message, Service};
/// Device Management Service.
pub struct Dms;
impl Service for Dms {
const ID: u32 = 0x02;
const VERSION: u8 = 1;
}
/// Reads the firmware revision.
struct GetRevision;
struct Revision(Utf8Bytes);
impl Request for GetRevision {
const ID: u16 = 0x0023;
type Response = Revision;
type Service = Dms;
fn encode(&self, _tlvs: &mut TlvWriter) {}
}
impl TryFrom<&Message> for Revision {
type Error = DecodeError;
fn try_from(message: &Message) -> Result<Self, DecodeError> {
message.get(0x01).map(Self)
}
}Required Associated Constants§
Provided Associated Constants§
Required Associated Types§
type Response: for<'a> TryFrom<&'a Message, Error = DecodeError>
type Response: for<'a> TryFrom<&'a Message, Error = DecodeError>
Response message.
Required Methods§
Provided Methods§
fn decode_response(response: Message) -> Result<Self::Response, Error>
fn decode_response(response: Message) -> Result<Self::Response, Error>
Checks and decodes the response.
The default reads the Status from TLV 0x02 and decodes the
response if it reports success.
§Errors
The default returns Error::Rejected if the status reports a
failure, or Error::Decode if the status or the response can’t be
decoded.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".