Struct safe_drive::service::client::Client
source · pub struct Client<T> { /* private fields */ }
Expand description
Client.
Implementations§
source§impl<T: ServiceMsg> Client<T>
impl<T: ServiceMsg> Client<T>
sourcepub fn send(self, data: &<T as ServiceMsg>::Request) -> RCLResult<ClientRecv<T>>
pub fn send(self, data: &<T as ServiceMsg>::Request) -> RCLResult<ClientRecv<T>>
Send a request.
§Example
use safe_drive::{
logger::Logger, msg::common_interfaces::std_srvs, pr_error, pr_info, pr_warn, service::client::Client,
};
use std::time::Duration;
async fn run_client(mut client: Client<std_srvs::srv::Empty>, logger: Logger) {
let dur = Duration::from_millis(100);
loop {
let request = std_srvs::srv::EmptyRequest::new().unwrap();
let mut receiver = client.send(&request).unwrap().recv();
match async_std::future::timeout(dur, &mut receiver).await {
Ok(Ok((c, response, _header))) => {
pr_info!(logger, "received: {:?}", response);
client = c;
}
Ok(Err(e)) => {
pr_error!(logger, "error: {e}");
break;
}
Err(_) => {
pr_warn!(logger, "timeout");
client = receiver.give_up();
}
}
}
}
§Errors
RCLError::InvalidArgument
if any arguments are invalid, orRCLError::ClientInvalid
if the client is invalid, orRCLError::Error
if an unspecified error occurs.
sourcepub fn send_ret_seq(
self,
data: &<T as ServiceMsg>::Request
) -> RCLResult<(ClientRecv<T>, i64)>
pub fn send_ret_seq( self, data: &<T as ServiceMsg>::Request ) -> RCLResult<(ClientRecv<T>, i64)>
send_ret_seq
is equivalent to send
, but this returns
the sequence number together.
§Example
use safe_drive::{
logger::Logger, msg::common_interfaces::std_srvs, pr_error, pr_info, pr_warn, service::client::Client,
};
use std::time::Duration;
async fn run_client(mut client: Client<std_srvs::srv::Empty>, logger: Logger) {
let dur = Duration::from_millis(100);
loop {
let request = std_srvs::srv::EmptyRequest::new().unwrap();
let (receiver, sequence) = client.send_ret_seq(&request).unwrap();
let mut receiver = receiver.recv();
pr_info!(logger, "sent: sequence = {sequence}");
match async_std::future::timeout(dur, &mut receiver).await {
Ok(Ok((c, response, _header))) => {
pr_info!(logger, "received: {:?}", response);
client = c;
}
Ok(Err(e)) => {
pr_error!(logger, "error: {e}");
break;
}
Err(_) => {
pr_warn!(logger, "timeout");
client = receiver.give_up();
}
}
}
}
§Errors
RCLError::InvalidArgument
if any arguments are invalid, orRCLError::ClientInvalid
if the client is invalid, orRCLError::Error
if an unspecified error occurs.
Auto Trait Implementations§
impl<T> Freeze for Client<T>
impl<T> !RefUnwindSafe for Client<T>
impl<T> Send for Client<T>where
T: Send,
impl<T> !Sync for Client<T>
impl<T> Unpin for Client<T>where
T: Unpin,
impl<T> UnwindSafe for Client<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more