From cd1bf6df4a992d50203385a488cb9ef7251eae5d Mon Sep 17 00:00:00 2001 From: smt923 Date: Sun, 10 Sep 2017 04:10:19 +0100 Subject: [PATCH 1/5] Added short examples for 'str::from_utf8_mut' --- src/libcore/str/mod.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 62e84c9ebd017..bac3d509c1714 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -302,6 +302,36 @@ pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> { } /// Converts a mutable slice of bytes to a mutable string slice. +/// +/// # Examples +/// +/// Basic usage: +/// +/// ``` +/// use std::str; +/// +/// // "Hello, Rust!" as a mutable vector +/// let mut hellorust = vec![72, 101, 108, 108, 111, 44, 32, 82, 117, 115, 116, 33]; +/// +/// // As we know these bytes are valid, we can use `unwrap()` +/// let outstr = str::from_utf8_mut(&mut hellorust).unwrap(); +/// +/// assert_eq!("Hello, Rust!", outstr); +/// ``` +/// +/// # Incorrect bytes: +/// +/// ``` +/// use std::str; +/// +/// // Some invalid bytes in a mutable vector +/// let mut invalid = vec![128, 223]; +/// +/// assert!(str::from_utf8_mut(&mut invalid).is_err()); +/// ``` +/// See the docs for [`Utf8Error`][error] for more details on the kinds of +/// errors that can be returned. +/// #[stable(feature = "str_mut_extras", since = "1.20.0")] pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> { run_utf8_validation(v)?; From 51bbd6957523fbda1db57fd0d92f356a0ed6ac08 Mon Sep 17 00:00:00 2001 From: smt923 Date: Sun, 10 Sep 2017 04:33:24 +0100 Subject: [PATCH 2/5] Fix incorrect markdown title --- src/libcore/str/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index bac3d509c1714..f0dde8fc342d9 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -319,7 +319,7 @@ pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> { /// assert_eq!("Hello, Rust!", outstr); /// ``` /// -/// # Incorrect bytes: +/// Incorrect bytes: /// /// ``` /// use std::str; From f20b030f02b1124cc3ff76cc906baba6588738e1 Mon Sep 17 00:00:00 2001 From: smt923 Date: Sun, 10 Sep 2017 14:08:20 +0100 Subject: [PATCH 3/5] Fix trailing whitespace --- src/libcore/str/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index f0dde8fc342d9..a9e72d6a4a8c5 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -331,7 +331,6 @@ pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> { /// ``` /// See the docs for [`Utf8Error`][error] for more details on the kinds of /// errors that can be returned. -/// #[stable(feature = "str_mut_extras", since = "1.20.0")] pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> { run_utf8_validation(v)?; From 303b7c2410d4b9039d0b5cb3badaa64e1cd0fede Mon Sep 17 00:00:00 2001 From: smt923 Date: Sun, 10 Sep 2017 14:12:23 +0100 Subject: [PATCH 4/5] Fix markdown link for Utf8Error --- src/libcore/str/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index a9e72d6a4a8c5..e731156afa0c4 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -318,7 +318,7 @@ pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> { /// /// assert_eq!("Hello, Rust!", outstr); /// ``` -/// +/// /// Incorrect bytes: /// /// ``` @@ -331,6 +331,8 @@ pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> { /// ``` /// See the docs for [`Utf8Error`][error] for more details on the kinds of /// errors that can be returned. +/// +/// [error]: struct.Utf8Error.html #[stable(feature = "str_mut_extras", since = "1.20.0")] pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> { run_utf8_validation(v)?; From 204414bcf4d3e040c1d3187dfaf6b5781b186ed0 Mon Sep 17 00:00:00 2001 From: smt923 Date: Sun, 10 Sep 2017 14:25:23 +0100 Subject: [PATCH 5/5] Actually fix the trailing whitespace --- src/libcore/str/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index e731156afa0c4..ce33160839076 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -323,7 +323,7 @@ pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> { /// /// ``` /// use std::str; -/// +/// /// // Some invalid bytes in a mutable vector /// let mut invalid = vec![128, 223]; ///