Struct safe_drive::service::server::ServerSend

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

Sender to send a response.

Implementations§

source§

impl<T: ServiceMsg> ServerSend<T>

source

pub fn send( self, data: &<T as ServiceMsg>::Response ) -> Result<Server<T>, (Self, RCLError)>

Send a response to the client.

§Errors
  • RCLError::InvalidArgument if any arguments are invalid, or
  • RCLError::ServiceInvalid if the service is invalid, or
  • RCLError::Error if an unspecified error occurs.
§Example
use safe_drive::{
    logger::Logger, msg::common_interfaces::std_srvs, pr_error, service::server::Server,
};

async fn server_task(mut server: Server<std_srvs::srv::Empty>, logger: Logger) {
    loop {
        // Call recv() by using timeout.
        let req = server.recv().await;
        match req {
            Ok((sender, request, _header)) => {
                let response = std_srvs::srv::EmptyResponse::new().unwrap();
                match sender.send(&response) {
                    Ok(s) => server = s,                  // Get a new server to handle next request.
                    Err((s, _e)) => server = s.give_up(), // Failed to send.
                }
            }
            Err(e) => {
                pr_error!(logger, "error: {e}");
                return;
            }
        }
    }
}
§Notes

data should be immutable, but rcl_send_response provided by ROS2 takes normal pointers instead of const pointers. So, currently, send takes data as mutable.

source

pub fn give_up(self) -> Server<T>

Auto Trait Implementations§

§

impl<T> Freeze for ServerSend<T>

§

impl<T> !RefUnwindSafe for ServerSend<T>

§

impl<T> Send for ServerSend<T>
where T: Send,

§

impl<T> !Sync for ServerSend<T>

§

impl<T> Unpin for ServerSend<T>
where T: Unpin,

§

impl<T> UnwindSafe for ServerSend<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.