1
1
//! A fixed capacity [`CString`](https://doc.rust-lang.org/std/ffi/struct.CString.html).
2
2
3
- use crate :: { vec:: Vec , CapacityError } ;
3
+ use crate :: { len_type :: DefaultLenType , vec:: Vec , CapacityError , LenType } ;
4
4
use core:: {
5
5
borrow:: Borrow ,
6
6
cmp:: Ordering ,
@@ -14,11 +14,11 @@ use core::{
14
14
///
15
15
/// It stores up to `N - 1` non-nul characters with a trailing nul terminator.
16
16
#[ derive( Clone , Hash ) ]
17
- pub struct CString < const N : usize > {
18
- inner : Vec < u8 , N > ,
17
+ pub struct CString < const N : usize , LenT : LenType = DefaultLenType < N > > {
18
+ inner : Vec < u8 , N , LenT > ,
19
19
}
20
20
21
- impl < const N : usize > CString < N > {
21
+ impl < const N : usize , LenT : LenType > CString < N , LenT > {
22
22
/// Creates a new C-compatible string with a terminating nul byte.
23
23
///
24
24
/// ```rust
@@ -264,28 +264,28 @@ impl<const N: usize> CString<N> {
264
264
}
265
265
}
266
266
267
- impl < const N : usize > AsRef < CStr > for CString < N > {
267
+ impl < const N : usize , LenT : LenType > AsRef < CStr > for CString < N , LenT > {
268
268
#[ inline]
269
269
fn as_ref ( & self ) -> & CStr {
270
270
self . as_c_str ( )
271
271
}
272
272
}
273
273
274
- impl < const N : usize > Borrow < CStr > for CString < N > {
274
+ impl < const N : usize , LenT : LenType > Borrow < CStr > for CString < N , LenT > {
275
275
#[ inline]
276
276
fn borrow ( & self ) -> & CStr {
277
277
self . as_c_str ( )
278
278
}
279
279
}
280
280
281
- impl < const N : usize > Default for CString < N > {
281
+ impl < const N : usize , LenT : LenType > Default for CString < N , LenT > {
282
282
#[ inline]
283
283
fn default ( ) -> Self {
284
284
Self :: new ( )
285
285
}
286
286
}
287
287
288
- impl < const N : usize > Deref for CString < N > {
288
+ impl < const N : usize , LenT : LenType > Deref for CString < N , LenT > {
289
289
type Target = CStr ;
290
290
291
291
#[ inline]
@@ -294,23 +294,27 @@ impl<const N: usize> Deref for CString<N> {
294
294
}
295
295
}
296
296
297
- impl < const N : usize , const M : usize > PartialEq < CString < M > > for CString < N > {
297
+ impl < const N : usize , const M : usize , LenT1 : LenType , LenT2 : LenType > PartialEq < CString < M , LenT2 > >
298
+ for CString < N , LenT1 >
299
+ {
298
300
#[ inline]
299
- fn eq ( & self , rhs : & CString < M > ) -> bool {
301
+ fn eq ( & self , rhs : & CString < M , LenT2 > ) -> bool {
300
302
self . as_c_str ( ) == rhs. as_c_str ( )
301
303
}
302
304
}
303
305
304
- impl < const N : usize > Eq for CString < N > { }
306
+ impl < const N : usize , LenT : LenType > Eq for CString < N , LenT > { }
305
307
306
- impl < const N : usize , const M : usize > PartialOrd < CString < M > > for CString < N > {
308
+ impl < const N : usize , const M : usize , LenT1 : LenType , LenT2 : LenType > PartialOrd < CString < M , LenT2 > >
309
+ for CString < N , LenT1 >
310
+ {
307
311
#[ inline]
308
- fn partial_cmp ( & self , rhs : & CString < M > ) -> Option < Ordering > {
312
+ fn partial_cmp ( & self , rhs : & CString < M , LenT2 > ) -> Option < Ordering > {
309
313
self . as_c_str ( ) . partial_cmp ( rhs. as_c_str ( ) )
310
314
}
311
315
}
312
316
313
- impl < const N : usize > Ord for CString < N > {
317
+ impl < const N : usize , LenT : LenType > Ord for CString < N , LenT > {
314
318
#[ inline]
315
319
fn cmp ( & self , rhs : & Self ) -> Ordering {
316
320
self . as_c_str ( ) . cmp ( rhs. as_c_str ( ) )
0 commit comments