Skip to content

Commit c9eb578

Browse files
nbdd0121ojeda
andauthored
typo and grammar fix
Co-authored-by: Miguel Ojeda <[email protected]>
1 parent 14f6e44 commit c9eb578

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

rust/kernel/str.rs

+20-19
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ macro_rules! b_str {
3535
/// Possible errors when using conversion functions in [`CStr`] and [`CBoundedStr`].
3636
#[derive(Debug, Clone, Copy)]
3737
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
3939
/// constructing a [`CBoundedStr`].
4040
BoundExceeded,
4141

@@ -254,10 +254,10 @@ macro_rules! c_str {
254254
}
255255

256256
/// 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
258258
/// on types.
259259
///
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`.
261261
/// This implies that even though `CBoundedStr<0>` is a well-formed type it cannot
262262
/// be safely created.
263263
#[repr(transparent)]
@@ -266,7 +266,7 @@ pub struct CBoundedStr<const N: usize>(CStr);
266266
impl<const N: usize> CBoundedStr<N> {
267267
/// Creates a [`CBoundedStr`] from a [`CStr`].
268268
///
269-
/// The provided `CStr` must be shorten than `N`.
269+
/// The provided [`CStr`] must be shorter than `N`.
270270
#[inline]
271271
pub const fn from_c_str(c_str: &CStr) -> Result<&Self, CStrConvertError> {
272272
if c_str.len_with_nul() > N {
@@ -282,16 +282,16 @@ impl<const N: usize> CBoundedStr<N> {
282282
///
283283
/// # Safety
284284
///
285-
/// The provided CStr must be shorten than `N`.
285+
/// The provided [`CStr`] must be shorter than `N`.
286286
#[inline]
287287
pub const unsafe fn from_c_str_unchecked(c_str: &CStr) -> &Self {
288288
&*(c_str as *const CStr as *const Self)
289289
}
290290

291291
/// Creates a [`CBoundedStr`] from a `[u8]`.
292292
///
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`.
295295
#[inline]
296296
pub fn from_bytes_with_nul(bytes: &[u8]) -> Result<&Self, CStrConvertError> {
297297
Self::from_c_str(CStr::from_bytes_with_nul(bytes)?)
@@ -302,8 +302,8 @@ impl<const N: usize> CBoundedStr<N> {
302302
///
303303
/// # Safety
304304
///
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`.
307307
#[inline]
308308
pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &Self {
309309
Self::from_c_str_unchecked(CStr::from_bytes_with_nul_unchecked(bytes))
@@ -314,7 +314,7 @@ impl<const N: usize> CBoundedStr<N> {
314314
///
315315
/// # Safety
316316
///
317-
/// The provided slice must be nul-terminated.
317+
/// The provided slice must be `NUL`-terminated.
318318
#[inline]
319319
pub const unsafe fn from_exact_bytes_with_nul_unchecked(bytes: &[u8; N]) -> &Self {
320320
Self::from_bytes_with_nul_unchecked(bytes)
@@ -329,8 +329,8 @@ impl<const N: usize> CBoundedStr<N> {
329329
unsafe { CBoundedStr::<M>::from_c_str_unchecked(&self.0) }
330330
}
331331

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.
334334
#[inline]
335335
pub const fn to_char_array(&self) -> [c_types::c_char; N] {
336336
let mut ret: [c_types::c_char; N] = [0; N];
@@ -342,7 +342,8 @@ impl<const N: usize> CBoundedStr<N> {
342342
ret
343343
}
344344

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.
346347
///
347348
/// `M` must be no less than the bound `N`.
348349
#[inline]
@@ -388,7 +389,7 @@ where
388389

389390
/// Creates a new [`CBoundedStr`] from a string literal.
390391
///
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
392393
/// exceed the bound supplied.
393394
///
394395
/// # Examples
@@ -399,15 +400,15 @@ where
399400
/// ```
400401
///
401402
/// ```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>`.
403404
/// const MY_CSTR: &'static CBoundedStr<100> = c_bounded_str!("My awesome CStr!");
404405
/// ```
405406
///
406407
/// ```rust,no_run
407408
/// // You can relax the bound using the `relax_bound` method.
408409
/// const MY_CSTR: &'static CBoundedStr<100> = c_bounded_str!("My awesome CStr!").relax_bound();
409410
///
410-
/// // Or alternatively specify a bound when invoking macro.
411+
/// // Or alternatively specify a bound.
411412
/// // In this case the supplied bound must be a constant expression.
412413
/// const MY_CSTR2: &'static CBoundedStr<100> = c_bounded_str!(100, "My awesome CStr!");
413414
///
@@ -416,9 +417,9 @@ where
416417
/// ```
417418
///
418419
/// ```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!");
422423
/// ```
423424
#[macro_export]
424425
macro_rules! c_bounded_str {

0 commit comments

Comments
 (0)