@@ -35,7 +35,7 @@ macro_rules! b_str {
35
35
/// Possible errors when using conversion functions in [`CStr`] and [`CBoundedStr`].
36
36
#[ derive( Debug , Clone , Copy ) ]
37
37
pub enum CStrConvertError {
38
- /// Supplied string length exceed the bound specified. Only happen when
38
+ /// Supplied string length exceeds the specified bound . Only happens when
39
39
/// constructing a [`CBoundedStr`].
40
40
BoundExceeded ,
41
41
@@ -254,10 +254,10 @@ macro_rules! c_str {
254
254
}
255
255
256
256
/// A `NUL`-terminated string that is guaranteed to be shorter than a given
257
- /// length. This type is useful because C- side usually impose maximum length
257
+ /// length. This type is useful because the C side usually imposes a maximum length
258
258
/// on types.
259
259
///
260
- /// The size parameter `N` represent the maximum number of bytes including NUL.
260
+ /// The size parameter `N` represents the maximum number of bytes including ` NUL` .
261
261
/// This implies that even though `CBoundedStr<0>` is a well-formed type it cannot
262
262
/// be safely created.
263
263
#[ repr( transparent) ]
@@ -266,7 +266,7 @@ pub struct CBoundedStr<const N: usize>(CStr);
266
266
impl < const N : usize > CBoundedStr < N > {
267
267
/// Creates a [`CBoundedStr`] from a [`CStr`].
268
268
///
269
- /// The provided `CStr` must be shorten than `N`.
269
+ /// The provided [ `CStr`] must be shorter than `N`.
270
270
#[ inline]
271
271
pub const fn from_c_str ( c_str : & CStr ) -> Result < & Self , CStrConvertError > {
272
272
if c_str. len_with_nul ( ) > N {
@@ -282,16 +282,16 @@ impl<const N: usize> CBoundedStr<N> {
282
282
///
283
283
/// # Safety
284
284
///
285
- /// The provided CStr must be shorten than `N`.
285
+ /// The provided [` CStr`] must be shorter than `N`.
286
286
#[ inline]
287
287
pub const unsafe fn from_c_str_unchecked ( c_str : & CStr ) -> & Self {
288
288
& * ( c_str as * const CStr as * const Self )
289
289
}
290
290
291
291
/// Creates a [`CBoundedStr`] from a `[u8]`.
292
292
///
293
- /// The provided slice must be nul -terminated, does not contain any
294
- /// interior nul bytes and be shorten than `N`.
293
+ /// The provided slice must be `NUL` -terminated, must not contain any
294
+ /// interior `NUL` bytes and must be shorter than `N`.
295
295
#[ inline]
296
296
pub fn from_bytes_with_nul ( bytes : & [ u8 ] ) -> Result < & Self , CStrConvertError > {
297
297
Self :: from_c_str ( CStr :: from_bytes_with_nul ( bytes) ?)
@@ -302,8 +302,8 @@ impl<const N: usize> CBoundedStr<N> {
302
302
///
303
303
/// # Safety
304
304
///
305
- /// The provided slice must be nul -terminated, does not contain any
306
- /// interior nul bytes and be shorten than `N`.
305
+ /// The provided slice must be `NUL` -terminated, must not contain any
306
+ /// interior `NUL` bytes and must be shorter than `N`.
307
307
#[ inline]
308
308
pub const unsafe fn from_bytes_with_nul_unchecked ( bytes : & [ u8 ] ) -> & Self {
309
309
Self :: from_c_str_unchecked ( CStr :: from_bytes_with_nul_unchecked ( bytes) )
@@ -314,7 +314,7 @@ impl<const N: usize> CBoundedStr<N> {
314
314
///
315
315
/// # Safety
316
316
///
317
- /// The provided slice must be nul -terminated.
317
+ /// The provided slice must be `NUL` -terminated.
318
318
#[ inline]
319
319
pub const unsafe fn from_exact_bytes_with_nul_unchecked ( bytes : & [ u8 ; N ] ) -> & Self {
320
320
Self :: from_bytes_with_nul_unchecked ( bytes)
@@ -329,8 +329,8 @@ impl<const N: usize> CBoundedStr<N> {
329
329
unsafe { CBoundedStr :: < M > :: from_c_str_unchecked ( & self . 0 ) }
330
330
}
331
331
332
- /// Converts the string to a c_char array with the current bound, fills the
333
- /// remaining bytes with zero.
332
+ /// Converts the string to a ` c_char` array of the same bound, filling
333
+ /// the remaining bytes with zero.
334
334
#[ inline]
335
335
pub const fn to_char_array ( & self ) -> [ c_types:: c_char ; N ] {
336
336
let mut ret: [ c_types:: c_char ; N ] = [ 0 ; N ] ;
@@ -342,7 +342,8 @@ impl<const N: usize> CBoundedStr<N> {
342
342
ret
343
343
}
344
344
345
- /// Expands the string a c_char array, fills remaining bytes with zero.
345
+ /// Expands the string to a `c_char` array of higher bound, filling
346
+ /// the remaining bytes with zero.
346
347
///
347
348
/// `M` must be no less than the bound `N`.
348
349
#[ inline]
@@ -388,7 +389,7 @@ where
388
389
389
390
/// Creates a new [`CBoundedStr`] from a string literal.
390
391
///
391
- /// The string literal should not contain any `NUL` bytes, and its length with NUL should not
392
+ /// The string literal should not contain any `NUL` bytes, and its length with ` NUL` should not
392
393
/// exceed the bound supplied.
393
394
///
394
395
/// # Examples
@@ -399,15 +400,15 @@ where
399
400
/// ```
400
401
///
401
402
/// ```rust,compile_fail
402
- /// // This would not compile as the type is `CBoundedStr<17>`.
403
+ /// // This does not compile as the inferred type is `CBoundedStr<17>`.
403
404
/// const MY_CSTR: &'static CBoundedStr<100> = c_bounded_str!("My awesome CStr!");
404
405
/// ```
405
406
///
406
407
/// ```rust,no_run
407
408
/// // You can relax the bound using the `relax_bound` method.
408
409
/// const MY_CSTR: &'static CBoundedStr<100> = c_bounded_str!("My awesome CStr!").relax_bound();
409
410
///
410
- /// // Or alternatively specify a bound when invoking macro .
411
+ /// // Or alternatively specify a bound.
411
412
/// // In this case the supplied bound must be a constant expression.
412
413
/// const MY_CSTR2: &'static CBoundedStr<100> = c_bounded_str!(100, "My awesome CStr!");
413
414
///
@@ -416,9 +417,9 @@ where
416
417
/// ```
417
418
///
418
419
/// ```rust,compile_fail
419
- /// // shouldn't compile as the string is longer than the specified bound.
420
- /// const MY_CSTR: &'static CBoundedStr<10 > = c_bounded_str!(10 , "My awesome CStr!");
421
- /// const MY_CSTR2: &'static CBoundedStr<10 > = c_bounded_str!(_, "My awesome CStr!");
420
+ /// // These do not compile as the string is longer than the specified bound.
421
+ /// const MY_CSTR: &'static CBoundedStr<4 > = c_bounded_str!(4 , "My awesome CStr!");
422
+ /// const MY_CSTR2: &'static CBoundedStr<4 > = c_bounded_str!(_, "My awesome CStr!");
422
423
/// ```
423
424
#[ macro_export]
424
425
macro_rules! c_bounded_str {
0 commit comments