From 93b5112c16ec79d545826b8af1c7c27535330e77 Mon Sep 17 00:00:00 2001 From: Denis Vasilik Date: Sat, 10 Nov 2018 10:23:11 +0100 Subject: [PATCH 1/4] Added comment for From trait implementation: boxed string slice to String --- src/liballoc/string.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 5c776292f53d7..50d2c04657a39 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2206,6 +2206,20 @@ impl<'a> From<&'a str> for String { #[cfg(not(test))] #[stable(feature = "string_from_box", since = "1.18.0")] impl From> for String { + /// Converts the given boxed `str` slice to a `String`. + /// It is notable that the `str` slice must be owned. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// let s1 : String = String::from("hello world"); + /// let s2 : Box = s1.into_boxed_str(); + /// let s3 : String = String::from(s2); + /// + /// assert_eq!("hello world", s3) + /// ``` fn from(s: Box) -> String { s.into_string() } From f0bfbd3e7201c59b5e155298fc4bdd0acece8992 Mon Sep 17 00:00:00 2001 From: Denis Vasilik Date: Sun, 11 Nov 2018 15:08:28 +0100 Subject: [PATCH 2/4] Added comments for trait implementations. --- src/liballoc/string.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 50d2c04657a39..27a14bd6b8cbe 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2207,7 +2207,7 @@ impl<'a> From<&'a str> for String { #[stable(feature = "string_from_box", since = "1.18.0")] impl From> for String { /// Converts the given boxed `str` slice to a `String`. - /// It is notable that the `str` slice must be owned. + /// It is notable that the `str` slice is owned. /// /// # Examples /// @@ -2227,6 +2227,19 @@ impl From> for String { #[stable(feature = "box_from_str", since = "1.20.0")] impl From for Box { + /// Converts the given `String` to a boxed `str` slice that is owned. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// let s1 = String::from("hello world"); + /// let s2 : Box = Box::from(s1); + /// let s3 : String = String::from(s2); + /// + /// assert_eq!("hello world", s3) + /// ``` fn from(s: String) -> Box { s.into_boxed_str() } @@ -2286,6 +2299,20 @@ impl<'a> FromIterator for Cow<'a, str> { #[stable(feature = "from_string_for_vec_u8", since = "1.14.0")] impl From for Vec { + /// Converts the given `String` to a vector `Vec` that holds values of type `u8`. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// let s1 = String::from("hello world"); + /// let v1 = Vec::from(s1); + /// + /// for b in v1 { + /// println!("{}", b); + /// } + /// ``` fn from(string: String) -> Vec { string.into_bytes() } From dc0fd65af23bec1de6ae0608c40f0bbcb52d4747 Mon Sep 17 00:00:00 2001 From: Denis Vasilik Date: Sun, 11 Nov 2018 16:58:00 +0100 Subject: [PATCH 3/4] Whitespace cleanup according to Rust's style guidelines. --- src/liballoc/string.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 27a14bd6b8cbe..e401951694cda 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2206,7 +2206,7 @@ impl<'a> From<&'a str> for String { #[cfg(not(test))] #[stable(feature = "string_from_box", since = "1.18.0")] impl From> for String { - /// Converts the given boxed `str` slice to a `String`. + /// Converts the given boxed `str` slice to a `String`. /// It is notable that the `str` slice is owned. /// /// # Examples @@ -2216,7 +2216,7 @@ impl From> for String { /// ``` /// let s1 : String = String::from("hello world"); /// let s2 : Box = s1.into_boxed_str(); - /// let s3 : String = String::from(s2); + /// let s3 : String = String::from(s2); /// /// assert_eq!("hello world", s3) /// ``` @@ -2308,7 +2308,7 @@ impl From for Vec { /// ``` /// let s1 = String::from("hello world"); /// let v1 = Vec::from(s1); - /// + /// /// for b in v1 { /// println!("{}", b); /// } From 6f3add34ca18cf6fbe5374d3e519b0c8838b1dfe Mon Sep 17 00:00:00 2001 From: Denis Vasilik Date: Sun, 11 Nov 2018 20:11:25 +0100 Subject: [PATCH 4/4] Minor style guide corrections. --- src/liballoc/string.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index e401951694cda..2beb3240aaca0 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2214,9 +2214,9 @@ impl From> for String { /// Basic usage: /// /// ``` - /// let s1 : String = String::from("hello world"); - /// let s2 : Box = s1.into_boxed_str(); - /// let s3 : String = String::from(s2); + /// let s1: String = String::from("hello world"); + /// let s2: Box = s1.into_boxed_str(); + /// let s3: String = String::from(s2); /// /// assert_eq!("hello world", s3) /// ``` @@ -2234,9 +2234,9 @@ impl From for Box { /// Basic usage: /// /// ``` - /// let s1 = String::from("hello world"); - /// let s2 : Box = Box::from(s1); - /// let s3 : String = String::from(s2); + /// let s1: String = String::from("hello world"); + /// let s2: Box = Box::from(s1); + /// let s3: String = String::from(s2); /// /// assert_eq!("hello world", s3) /// ```