safe_drive 0.4.3

safe_drive: Formally Specified Rust Bindings for ROS2
Documentation
// This file was automatically generated by ros2msg_to_rs (https://github.com/tier4/ros2msg_to_rs).
use super::super::super::*;
use super::super::*;
use crate::msg::common_interfaces::*;
use crate::msg::*;
use crate::rcl;
pub const ERROR_NONE: i8 = 0;
pub const ERROR_REJECTED: i8 = 1;
pub const ERROR_UNKNOWN_GOAL_ID: i8 = 2;
pub const ERROR_GOAL_TERMINATED: i8 = 3;

extern "C" {
    fn action_msgs__srv__CancelGoal_Request__init(msg: *mut CancelGoalRequest) -> bool;
    fn action_msgs__srv__CancelGoal_Request__fini(msg: *mut CancelGoalRequest);
    fn action_msgs__srv__CancelGoal_Request__Sequence__init(
        msg: *mut CancelGoalRequestSeqRaw,
        size: usize,
    ) -> bool;
    fn action_msgs__srv__CancelGoal_Request__Sequence__fini(msg: *mut CancelGoalRequestSeqRaw);
    fn action_msgs__srv__CancelGoal_Response__init(msg: *mut CancelGoalResponse) -> bool;
    fn action_msgs__srv__CancelGoal_Response__fini(msg: *mut CancelGoalResponse);
    fn action_msgs__srv__CancelGoal_Response__Sequence__init(
        msg: *mut CancelGoalResponseSeqRaw,
        size: usize,
    ) -> bool;
    fn action_msgs__srv__CancelGoal_Response__Sequence__fini(msg: *mut CancelGoalResponseSeqRaw);
    fn rosidl_typesupport_c__get_service_type_support_handle__action_msgs__srv__CancelGoal(
    ) -> *const rcl::rosidl_service_type_support_t;
    fn rosidl_typesupport_c__get_message_type_support_handle__action_msgs__srv__CancelGoal_Request(
    ) -> *const rcl::rosidl_message_type_support_t;
    fn rosidl_typesupport_c__get_message_type_support_handle__action_msgs__srv__CancelGoal_Response(
    ) -> *const rcl::rosidl_message_type_support_t;
}

#[repr(C)]
#[derive(Debug)]
pub struct CancelGoalRequest {
    pub goal_info: GoalInfo,
}

#[repr(C)]
#[derive(Debug)]
pub struct CancelGoalResponse {
    pub return_code: i8,
    pub goals_canceling: GoalInfoSeq<0>,
}

impl CancelGoalRequest {
    pub fn new() -> Option<Self> {
        let mut msg: Self = unsafe { std::mem::MaybeUninit::zeroed().assume_init() };
        if unsafe { action_msgs__srv__CancelGoal_Request__init(&mut msg) } {
            Some(msg)
        } else {
            None
        }
    }
}

impl Drop for CancelGoalRequest {
    fn drop(&mut self) {
        unsafe { action_msgs__srv__CancelGoal_Request__fini(self) };
    }
}

#[repr(C)]
#[derive(Debug)]
struct CancelGoalRequestSeqRaw {
    data: *mut CancelGoalRequest,
    size: usize,
    capacity: usize,
}

/// Sequence of CancelGoalRequest.
/// `N` is the maximum number of elements.
/// If `N` is `0`, the size is unlimited.
#[repr(C)]
#[derive(Debug)]
pub struct CancelGoalRequestSeq<const N: usize> {
    data: *mut CancelGoalRequest,
    size: usize,
    capacity: usize,
}

impl<const N: usize> CancelGoalRequestSeq<N> {
    /// Create a sequence of.
    /// `N` represents the maximum number of elements.
    /// If `N` is `0`, the sequence is unlimited.
    pub fn new(size: usize) -> Option<Self> {
        if N != 0 && size >= N {
            // the size exceeds in the maximum number
            return None;
        }

        let mut msg: CancelGoalRequestSeqRaw =
            unsafe { std::mem::MaybeUninit::zeroed().assume_init() };
        if unsafe { action_msgs__srv__CancelGoal_Request__Sequence__init(&mut msg, size) } {
            Some(Self {
                data: msg.data,
                size: msg.size,
                capacity: msg.capacity,
            })
        } else {
            None
        }
    }

    pub fn null() -> Self {
        let msg: CancelGoalRequestSeqRaw = unsafe { std::mem::MaybeUninit::zeroed().assume_init() };
        Self {
            data: msg.data,
            size: msg.size,
            capacity: msg.capacity,
        }
    }

    pub fn as_slice(&self) -> &[CancelGoalRequest] {
        if self.data.is_null() {
            &[]
        } else {
            let s = unsafe { std::slice::from_raw_parts(self.data, self.size) };
            s
        }
    }

    pub fn as_slice_mut(&mut self) -> &mut [CancelGoalRequest] {
        if self.data.is_null() {
            &mut []
        } else {
            let s = unsafe { std::slice::from_raw_parts_mut(self.data, self.size) };
            s
        }
    }

    pub fn iter(&self) -> std::slice::Iter<'_, CancelGoalRequest> {
        self.as_slice().iter()
    }

    pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, CancelGoalRequest> {
        self.as_slice_mut().iter_mut()
    }

    pub fn len(&self) -> usize {
        self.as_slice().len()
    }

    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }
}

impl<const N: usize> Drop for CancelGoalRequestSeq<N> {
    fn drop(&mut self) {
        let mut msg = CancelGoalRequestSeqRaw {
            data: self.data,
            size: self.size,
            capacity: self.capacity,
        };
        unsafe { action_msgs__srv__CancelGoal_Request__Sequence__fini(&mut msg) };
    }
}

unsafe impl<const N: usize> Send for CancelGoalRequestSeq<N> {}
unsafe impl<const N: usize> Sync for CancelGoalRequestSeq<N> {}

impl CancelGoalResponse {
    pub fn new() -> Option<Self> {
        let mut msg: Self = unsafe { std::mem::MaybeUninit::zeroed().assume_init() };
        if unsafe { action_msgs__srv__CancelGoal_Response__init(&mut msg) } {
            Some(msg)
        } else {
            None
        }
    }
}

impl Drop for CancelGoalResponse {
    fn drop(&mut self) {
        unsafe { action_msgs__srv__CancelGoal_Response__fini(self) };
    }
}

#[repr(C)]
#[derive(Debug)]
struct CancelGoalResponseSeqRaw {
    data: *mut CancelGoalResponse,
    size: usize,
    capacity: usize,
}

/// Sequence of CancelGoalResponse.
/// `N` is the maximum number of elements.
/// If `N` is `0`, the size is unlimited.
#[repr(C)]
#[derive(Debug)]
pub struct CancelGoalResponseSeq<const N: usize> {
    data: *mut CancelGoalResponse,
    size: usize,
    capacity: usize,
}

impl<const N: usize> CancelGoalResponseSeq<N> {
    /// Create a sequence of.
    /// `N` represents the maximum number of elements.
    /// If `N` is `0`, the sequence is unlimited.
    pub fn new(size: usize) -> Option<Self> {
        if N != 0 && size >= N {
            // the size exceeds in the maximum number
            return None;
        }

        let mut msg: CancelGoalResponseSeqRaw =
            unsafe { std::mem::MaybeUninit::zeroed().assume_init() };
        if unsafe { action_msgs__srv__CancelGoal_Response__Sequence__init(&mut msg, size) } {
            Some(Self {
                data: msg.data,
                size: msg.size,
                capacity: msg.capacity,
            })
        } else {
            None
        }
    }

    pub fn null() -> Self {
        let msg: CancelGoalResponseSeqRaw =
            unsafe { std::mem::MaybeUninit::zeroed().assume_init() };
        Self {
            data: msg.data,
            size: msg.size,
            capacity: msg.capacity,
        }
    }

    pub fn as_slice(&self) -> &[CancelGoalResponse] {
        if self.data.is_null() {
            &[]
        } else {
            let s = unsafe { std::slice::from_raw_parts(self.data, self.size) };
            s
        }
    }

    pub fn as_slice_mut(&mut self) -> &mut [CancelGoalResponse] {
        if self.data.is_null() {
            &mut []
        } else {
            let s = unsafe { std::slice::from_raw_parts_mut(self.data, self.size) };
            s
        }
    }

    pub fn iter(&self) -> std::slice::Iter<'_, CancelGoalResponse> {
        self.as_slice().iter()
    }

    pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, CancelGoalResponse> {
        self.as_slice_mut().iter_mut()
    }

    pub fn len(&self) -> usize {
        self.as_slice().len()
    }

    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }
}

impl<const N: usize> Drop for CancelGoalResponseSeq<N> {
    fn drop(&mut self) {
        let mut msg = CancelGoalResponseSeqRaw {
            data: self.data,
            size: self.size,
            capacity: self.capacity,
        };
        unsafe { action_msgs__srv__CancelGoal_Response__Sequence__fini(&mut msg) };
    }
}

unsafe impl<const N: usize> Send for CancelGoalResponseSeq<N> {}
unsafe impl<const N: usize> Sync for CancelGoalResponseSeq<N> {}

pub struct CancelGoal;

impl ServiceMsg for CancelGoal {
    type Request = CancelGoalRequest;
    type Response = CancelGoalResponse;
    fn type_support() -> *const rcl::rosidl_service_type_support_t {
        unsafe {
            rosidl_typesupport_c__get_service_type_support_handle__action_msgs__srv__CancelGoal()
        }
    }
}

impl TypeSupport for CancelGoalRequest {
    fn type_support() -> *const rcl::rosidl_message_type_support_t {
        unsafe {
            rosidl_typesupport_c__get_message_type_support_handle__action_msgs__srv__CancelGoal_Request()
        }
    }
}

impl TypeSupport for CancelGoalResponse {
    fn type_support() -> *const rcl::rosidl_message_type_support_t {
        unsafe {
            rosidl_typesupport_c__get_message_type_support_handle__action_msgs__srv__CancelGoal_Response()
        }
    }
}