Skip to content

Commit 93b5112

Browse files
committed
Added comment for From trait implementation: boxed string slice to String
1 parent 0366cca commit 93b5112

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/liballoc/string.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,20 @@ impl<'a> From<&'a str> for String {
22062206
#[cfg(not(test))]
22072207
#[stable(feature = "string_from_box", since = "1.18.0")]
22082208
impl From<Box<str>> for String {
2209+
/// Converts the given boxed `str` slice to a `String`.
2210+
/// It is notable that the `str` slice must be owned.
2211+
///
2212+
/// # Examples
2213+
///
2214+
/// Basic usage:
2215+
///
2216+
/// ```
2217+
/// let s1 : String = String::from("hello world");
2218+
/// let s2 : Box<str> = s1.into_boxed_str();
2219+
/// let s3 : String = String::from(s2);
2220+
///
2221+
/// assert_eq!("hello world", s3)
2222+
/// ```
22092223
fn from(s: Box<str>) -> String {
22102224
s.into_string()
22112225
}

0 commit comments

Comments
 (0)