@@ -29,9 +29,9 @@ use crate::traits::SequenceAlloc;
2929pub struct String {
3030 /// Dynamic memory in this type is allocated and deallocated by C, but this is a detail that is managed by
3131 /// 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 ,
3535}
3636
3737/// A zero-terminated string of 16-bit characters.
@@ -50,9 +50,9 @@ pub struct String {
5050/// ```
5151#[ repr( C ) ]
5252pub 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 ,
5656}
5757
5858/// A zero-terminated string of 8-bit characters with a length limit.
@@ -117,9 +117,13 @@ macro_rules! string_impl {
117117 extern "C" {
118118 fn $init( s: * mut $string) -> bool ;
119119 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 ;
122122 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 ;
123127 }
124128
125129 impl Default for $string {
@@ -226,7 +230,7 @@ macro_rules! string_impl {
226230 unsafe impl Sync for $string { }
227231
228232 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 {
230234 // SAFETY: There are no special preconditions to the sequence_init function.
231235 unsafe { $sequence_init( seq as * mut _, size) }
232236 }
@@ -235,17 +239,16 @@ macro_rules! string_impl {
235239 unsafe { $sequence_fini( seq as * mut _) }
236240 }
237241 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 _) }
241244 }
242245 }
243246 } ;
244247}
245248
246249string_impl ! (
247250 String ,
248- libc :: c_char,
251+ std :: os :: raw :: c_char,
249252 u8 ,
250253 from_utf8_lossy,
251254 rosidl_runtime_c__String__init,
@@ -257,7 +260,7 @@ string_impl!(
257260) ;
258261string_impl ! (
259262 WString ,
260- libc :: c_ushort,
263+ std :: os :: raw :: c_ushort,
261264 u16 ,
262265 from_utf16_lossy,
263266 rosidl_runtime_c__U16String__init,
@@ -330,7 +333,7 @@ impl<const N: usize> Debug for BoundedString<N> {
330333}
331334
332335impl < const N : usize > Deref for BoundedString < N > {
333- type Target = [ libc :: c_char ] ;
336+ type Target = [ std :: os :: raw :: c_char ] ;
334337 fn deref ( & self ) -> & Self :: Target {
335338 self . inner . deref ( )
336339 }
@@ -349,7 +352,7 @@ impl<const N: usize> Display for BoundedString<N> {
349352}
350353
351354impl < 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 {
353356 // SAFETY: There are no special preconditions to the rosidl_runtime_c__String__Sequence__init function.
354357 unsafe {
355358 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> {
415418}
416419
417420impl < 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 {
419422 // SAFETY: There are no special preconditions to the rosidl_runtime_c__U16String__Sequence__init function.
420423 unsafe {
421424 rosidl_runtime_c__U16String__Sequence__init ( seq as * mut Sequence < Self > as * mut _ , size)
0 commit comments