Struct safe_drive::service::client::Client

source ·
pub struct Client<T> { /* private fields */ }
Expand description

Client.

Implementations§

source§

impl<T: ServiceMsg> Client<T>

source

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, or
  • RCLError::ClientInvalid if the client is invalid, or
  • RCLError::Error if an unspecified error occurs.
source

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, or
  • RCLError::ClientInvalid if the client is invalid, or
  • RCLError::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> 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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>,

§

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.