Struct Client

Source
pub struct Client<T>
where T: Service,
{ /* private fields */ }
Expand description

Main class responsible for sending requests to a ROS service.

The only available way to instantiate clients is via Node::create_client, this is to ensure that Nodes can track all the clients that have been created.

Implementations§

Source§

impl<T> Client<T>
where T: Service,

Source

pub fn async_send_request_with_callback<'a, M: MessageCow<'a, T::Request>, F>( &self, message: M, callback: F, ) -> Result<(), RclrsError>
where F: FnOnce(T::Response) + 'static + Send,

Sends a request with a callback to be called with the response.

The MessageCow trait is implemented by any Message as well as any reference to a Message.

The reason for allowing owned messages is that publishing owned messages can be more efficient in the case of idiomatic messages1.

Hence, when a message will not be needed anymore after publishing, pass it by value. When a message will be needed again after publishing, pass it by reference, instead of cloning and passing by value.


  1. See the Message trait for an explanation of “idiomatic”. 

Source

pub async fn call_async<'a, R: MessageCow<'a, T::Request>>( &self, request: R, ) -> Result<T::Response, RclrsError>
where T: Service,

Sends a request and returns the response as a Future.

The MessageCow trait is implemented by any Message as well as any reference to a Message.

The reason for allowing owned messages is that publishing owned messages can be more efficient in the case of idiomatic messages1.

Hence, when a message will not be needed anymore after publishing, pass it by value. When a message will be needed again after publishing, pass it by reference, instead of cloning and passing by value.


  1. See the Message trait for an explanation of “idiomatic”. 

Source

pub fn take_response( &self, ) -> Result<(T::Response, rmw_request_id_t), RclrsError>

Fetches a new response.

When there is no new message, this will return a ClientTakeFailed.

Source

pub fn service_is_ready(&self) -> Result<bool, RclrsError>

Check if a service server is available.

Will return true if there is a service server available, false if unavailable.

Trait Implementations§

Source§

impl<T> ClientBase for Client<T>
where T: Service,

Source§

fn handle(&self) -> &ClientHandle

Internal function to get a reference to the rcl handle.
Source§

fn execute(&self) -> Result<(), RclrsError>

Tries to take a new response and run the callback or future with it.

Auto Trait Implementations§

§

impl<T> !Freeze for Client<T>

§

impl<T> RefUnwindSafe for Client<T>

§

impl<T> Send for Client<T>

§

impl<T> Sync for Client<T>

§

impl<T> Unpin for Client<T>

§

impl<T> UnwindSafe for Client<T>

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

Source§

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

Source§

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.