mod client;
mod simple_client;
pub use client::Client;
pub use simple_client::SimpleClient;
use crate::{AtatCmd, Error};
pub trait AtatClient {
async fn send<Cmd: AtatCmd>(&mut self, cmd: &Cmd) -> Result<Cmd::Response, Error>;
async fn send_retry<Cmd: AtatCmd>(&mut self, cmd: &Cmd) -> Result<Cmd::Response, Error> {
for attempt in 1..=Cmd::ATTEMPTS {
if attempt > 1 {
debug!("Attempt {}:", attempt);
}
match self.send(cmd).await {
Err(Error::Timeout) => {}
Err(Error::Parse) => {
if !Cmd::REATTEMPT_ON_PARSE_ERR {
return Err(Error::Parse);
}
}
r => return r,
}
}
Err(Error::Timeout)
}
}
impl<T> AtatClient for &mut T
where
T: AtatClient,
{
async fn send<Cmd: AtatCmd>(&mut self, cmd: &Cmd) -> Result<Cmd::Response, Error> {
T::send(self, cmd).await
}
}