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