@@ -29,9 +29,9 @@ use crate::traits::SequenceAlloc;
29
29
pub struct String {
30
30
/// Dynamic memory in this type is allocated and deallocated by C, but this is a detail that is managed by
31
31
/// the relevant functions and trait impls.
32
- data : * mut libc :: c_char ,
33
- size : libc :: size_t ,
34
- capacity : libc :: size_t ,
32
+ data : * mut std :: os :: raw :: c_char ,
33
+ size : usize ,
34
+ capacity : usize ,
35
35
}
36
36
37
37
/// A zero-terminated string of 16-bit characters.
@@ -50,9 +50,9 @@ pub struct String {
50
50
/// ```
51
51
#[ repr( C ) ]
52
52
pub struct WString {
53
- data : * mut libc :: c_ushort ,
54
- size : libc :: size_t ,
55
- capacity : libc :: size_t ,
53
+ data : * mut std :: os :: raw :: c_ushort ,
54
+ size : usize ,
55
+ capacity : usize ,
56
56
}
57
57
58
58
/// A zero-terminated string of 8-bit characters with a length limit.
@@ -117,9 +117,13 @@ macro_rules! string_impl {
117
117
extern "C" {
118
118
fn $init( s: * mut $string) -> bool ;
119
119
fn $fini( s: * mut $string) ;
120
- fn $assignn( s: * mut $string, value: * const $char_type, n: libc :: size_t ) -> bool ;
121
- fn $sequence_init( seq: * mut Sequence <$string>, size: libc :: size_t ) -> bool ;
120
+ fn $assignn( s: * mut $string, value: * const $char_type, n: usize ) -> bool ;
121
+ fn $sequence_init( seq: * mut Sequence <$string>, size: usize ) -> bool ;
122
122
fn $sequence_fini( seq: * mut Sequence <$string>) ;
123
+ fn $sequence_copy(
124
+ in_seq: * const Sequence <$string>,
125
+ out_seq: * mut Sequence <$string>,
126
+ ) -> bool ;
123
127
}
124
128
125
129
impl Default for $string {
@@ -226,7 +230,7 @@ macro_rules! string_impl {
226
230
unsafe impl Sync for $string { }
227
231
228
232
impl SequenceAlloc for $string {
229
- fn sequence_init( seq: & mut Sequence <Self >, size: libc :: size_t ) -> bool {
233
+ fn sequence_init( seq: & mut Sequence <Self >, size: usize ) -> bool {
230
234
// SAFETY: There are no special preconditions to the sequence_init function.
231
235
unsafe { $sequence_init( seq as * mut _, size) }
232
236
}
@@ -235,17 +239,16 @@ macro_rules! string_impl {
235
239
unsafe { $sequence_fini( seq as * mut _) }
236
240
}
237
241
fn sequence_copy( in_seq: & Sequence <Self >, out_seq: & mut Sequence <Self >) -> bool {
238
- out_seq. resize_to_at_least( in_seq. len( ) ) ;
239
- out_seq. clone_from_slice( in_seq. as_slice( ) ) ;
240
- true
242
+ // SAFETY: There are no special preconditions to the sequence_copy function.
243
+ unsafe { $sequence_copy( in_seq as * const _, out_seq as * mut _) }
241
244
}
242
245
}
243
246
} ;
244
247
}
245
248
246
249
string_impl ! (
247
250
String ,
248
- libc :: c_char,
251
+ std :: os :: raw :: c_char,
249
252
u8 ,
250
253
from_utf8_lossy,
251
254
rosidl_runtime_c__String__init,
@@ -257,7 +260,7 @@ string_impl!(
257
260
) ;
258
261
string_impl ! (
259
262
WString ,
260
- libc :: c_ushort,
263
+ std :: os :: raw :: c_ushort,
261
264
u16 ,
262
265
from_utf16_lossy,
263
266
rosidl_runtime_c__U16String__init,
@@ -330,7 +333,7 @@ impl<const N: usize> Debug for BoundedString<N> {
330
333
}
331
334
332
335
impl < const N : usize > Deref for BoundedString < N > {
333
- type Target = [ libc :: c_char ] ;
336
+ type Target = [ std :: os :: raw :: c_char ] ;
334
337
fn deref ( & self ) -> & Self :: Target {
335
338
self . inner . deref ( )
336
339
}
@@ -349,7 +352,7 @@ impl<const N: usize> Display for BoundedString<N> {
349
352
}
350
353
351
354
impl < const N : usize > SequenceAlloc for BoundedString < N > {
352
- fn sequence_init ( seq : & mut Sequence < Self > , size : libc :: size_t ) -> bool {
355
+ fn sequence_init ( seq : & mut Sequence < Self > , size : usize ) -> bool {
353
356
// SAFETY: There are no special preconditions to the rosidl_runtime_c__String__Sequence__init function.
354
357
unsafe {
355
358
rosidl_runtime_c__String__Sequence__init ( seq as * mut Sequence < Self > as * mut _ , size)
@@ -415,7 +418,7 @@ impl<const N: usize> Display for BoundedWString<N> {
415
418
}
416
419
417
420
impl < const N : usize > SequenceAlloc for BoundedWString < N > {
418
- fn sequence_init ( seq : & mut Sequence < Self > , size : libc :: size_t ) -> bool {
421
+ fn sequence_init ( seq : & mut Sequence < Self > , size : usize ) -> bool {
419
422
// SAFETY: There are no special preconditions to the rosidl_runtime_c__U16String__Sequence__init function.
420
423
unsafe {
421
424
rosidl_runtime_c__U16String__Sequence__init ( seq as * mut Sequence < Self > as * mut _ , size)
0 commit comments