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