safe_drive/msg/jazzy/common_interfaces/geometry_msgs/msg/
point_32.rs

1// This file was automatically generated by ros2msg_to_rs (https://github.com/tier4/ros2msg_to_rs).
2use super::super::super::*;
3use super::*;
4use crate::msg::*;
5use crate::rcl;
6
7extern "C" {
8    fn geometry_msgs__msg__Point32__init(msg: *mut Point32) -> bool;
9    fn geometry_msgs__msg__Point32__fini(msg: *mut Point32);
10    fn geometry_msgs__msg__Point32__are_equal(lhs: *const Point32, rhs: *const Point32) -> bool;
11    fn geometry_msgs__msg__Point32__Sequence__init(msg: *mut Point32SeqRaw, size: usize) -> bool;
12    fn geometry_msgs__msg__Point32__Sequence__fini(msg: *mut Point32SeqRaw);
13    fn geometry_msgs__msg__Point32__Sequence__are_equal(
14        lhs: *const Point32SeqRaw,
15        rhs: *const Point32SeqRaw,
16    ) -> bool;
17    fn rosidl_typesupport_c__get_message_type_support_handle__geometry_msgs__msg__Point32(
18    ) -> *const rcl::rosidl_message_type_support_t;
19}
20
21#[repr(C)]
22#[derive(Debug)]
23pub struct Point32 {
24    pub x: f32,
25    pub y: f32,
26    pub z: f32,
27}
28
29impl Point32 {
30    pub fn new() -> Option<Self> {
31        let mut msg: Self = unsafe { std::mem::MaybeUninit::zeroed().assume_init() };
32        if unsafe { geometry_msgs__msg__Point32__init(&mut msg) } {
33            Some(msg)
34        } else {
35            None
36        }
37    }
38}
39
40impl Drop for Point32 {
41    fn drop(&mut self) {
42        unsafe { geometry_msgs__msg__Point32__fini(self) };
43    }
44}
45
46#[repr(C)]
47#[derive(Debug)]
48struct Point32SeqRaw {
49    data: *mut Point32,
50    size: size_t,
51    capacity: size_t,
52}
53
54/// Sequence of Point32.
55/// `N` is the maximum number of elements.
56/// If `N` is `0`, the size is unlimited.
57#[repr(C)]
58#[derive(Debug)]
59pub struct Point32Seq<const N: usize> {
60    data: *mut Point32,
61    size: size_t,
62    capacity: size_t,
63}
64
65impl<const N: usize> Point32Seq<N> {
66    /// Create a sequence of.
67    /// `N` represents the maximum number of elements.
68    /// If `N` is `0`, the sequence is unlimited.
69    pub fn new(size: usize) -> Option<Self> {
70        if N != 0 && size > N {
71            // the size exceeds in the maximum number
72            return None;
73        }
74
75        let mut msg: Point32SeqRaw = unsafe { std::mem::MaybeUninit::zeroed().assume_init() };
76        if unsafe { geometry_msgs__msg__Point32__Sequence__init(&mut msg, size) } {
77            Some(Self {
78                data: msg.data,
79                size: msg.size,
80                capacity: msg.capacity,
81            })
82        } else {
83            None
84        }
85    }
86
87    pub fn null() -> Self {
88        let msg: Point32SeqRaw = unsafe { std::mem::MaybeUninit::zeroed().assume_init() };
89        Self {
90            data: msg.data,
91            size: msg.size,
92            capacity: msg.capacity,
93        }
94    }
95
96    pub fn as_slice(&self) -> &[Point32] {
97        if self.data.is_null() {
98            &[]
99        } else {
100            let s = unsafe { std::slice::from_raw_parts(self.data, self.size as _) };
101            s
102        }
103    }
104
105    pub fn as_slice_mut(&mut self) -> &mut [Point32] {
106        if self.data.is_null() {
107            &mut []
108        } else {
109            let s = unsafe { std::slice::from_raw_parts_mut(self.data, self.size as _) };
110            s
111        }
112    }
113
114    pub fn iter(&self) -> std::slice::Iter<'_, Point32> {
115        self.as_slice().iter()
116    }
117
118    pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, Point32> {
119        self.as_slice_mut().iter_mut()
120    }
121
122    pub fn len(&self) -> usize {
123        self.as_slice().len()
124    }
125
126    pub fn is_empty(&self) -> bool {
127        self.len() == 0
128    }
129}
130
131impl<const N: usize> Drop for Point32Seq<N> {
132    fn drop(&mut self) {
133        let mut msg = Point32SeqRaw {
134            data: self.data,
135            size: self.size,
136            capacity: self.capacity,
137        };
138        unsafe { geometry_msgs__msg__Point32__Sequence__fini(&mut msg) };
139    }
140}
141
142unsafe impl<const N: usize> Send for Point32Seq<N> {}
143unsafe impl<const N: usize> Sync for Point32Seq<N> {}
144
145impl TypeSupport for Point32 {
146    fn type_support() -> *const rcl::rosidl_message_type_support_t {
147        unsafe {
148            rosidl_typesupport_c__get_message_type_support_handle__geometry_msgs__msg__Point32()
149        }
150    }
151}
152
153impl PartialEq for Point32 {
154    fn eq(&self, other: &Self) -> bool {
155        unsafe { geometry_msgs__msg__Point32__are_equal(self, other) }
156    }
157}
158
159impl<const N: usize> PartialEq for Point32Seq<N> {
160    fn eq(&self, other: &Self) -> bool {
161        unsafe {
162            let msg1 = Point32SeqRaw {
163                data: self.data,
164                size: self.size,
165                capacity: self.capacity,
166            };
167            let msg2 = Point32SeqRaw {
168                data: other.data,
169                size: other.size,
170                capacity: other.capacity,
171            };
172            geometry_msgs__msg__Point32__Sequence__are_equal(&msg1, &msg2)
173        }
174    }
175}