Skip to content

Commit a5d1bf1

Browse files
committed
docs: improve and add missing doc comment
1 parent a04bfe4 commit a5d1bf1

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

src/errors/from_utf16_error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use core::{error::Error, fmt};
22

3+
/// An error if the conversion from a sequence of UTF-16 code units to a [`LeanString`] fails due
4+
/// to invalid UTF-16 code unit sequences.
5+
///
6+
/// [`LeanString`]: crate::LeanString
37
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
48
pub struct FromUtf16Error;
59

src/errors/reserve_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::{error::Error, fmt};
22

3-
/// A possible error value if allocating or resizing a [`LeanString`] failed.
3+
/// An error if allocating or resizing a [`LeanString`] failed.
44
///
55
/// [`LeanString`]: crate::LeanString
66
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

src/errors/to_lean_string_error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ use core::{error::Error, fmt};
22

33
use super::ReserveError;
44

5+
/// An error that can occur when converting a value to a [`LeanString`].
6+
///
7+
/// This error can be caused by either a reserve error when allocating memory,
8+
/// or a formatting error when converting the value to a string.
9+
///
10+
/// [`LeanString`]: crate::LeanString
511
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
612
pub enum ToLeanStringError {
13+
/// An error occurred while trying to allocate memory.
714
Reserve(ReserveError),
15+
/// A formatting error occurred during conversion.
816
Fmt(fmt::Error),
917
}
1018

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub use traits::ToLeanString;
3232

3333
mod features;
3434

35+
/// Compact, clone-on-write, UTF-8 encoded, growable string type.
3536
#[repr(transparent)]
3637
pub struct LeanString(Repr);
3738

@@ -123,8 +124,8 @@ impl LeanString {
123124

124125
/// Fallible version of [`LeanString::with_capacity()`].
125126
///
126-
/// This method won't panic if the system is out-of-memory, or the `capacity` is too large, but
127-
/// return an [`ReserveError`]. Otherwise it behaves the same as [`LeanString::with_capacity()`].
127+
/// This method won't panic if the system is out of memory, or if the `capacity` is too large, but
128+
/// returns a [`ReserveError`]. Otherwise it behaves the same as [`LeanString::with_capacity()`].
128129
#[inline]
129130
pub fn try_with_capacity(capacity: usize) -> Result<Self, ReserveError> {
130131
Repr::with_capacity(capacity).map(LeanString)

src/traits.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@ use core::{fmt, fmt::Write, num::NonZero};
55

66
/// A trait for converting a value to a [`LeanString`].
77
pub trait ToLeanString {
8+
/// Converts the value to a [`LeanString`].
9+
///
10+
/// # Panics
11+
///
12+
/// Panics if conversion fails. For a non-panicking version, use [`try_to_lean_string`].
13+
///
14+
/// [`try_to_lean_string`]: Self::try_to_lean_string
815
fn to_lean_string(&self) -> LeanString {
916
self.try_to_lean_string().unwrap_with_msg()
1017
}
1118

19+
/// Attempts to convert the value to a [`LeanString`].
20+
///
21+
/// # Errors
22+
///
23+
/// Returns a [`ToLeanStringError`] if the conversion fails.
1224
fn try_to_lean_string(&self) -> Result<LeanString, ToLeanStringError>;
1325
}
1426

0 commit comments

Comments
 (0)