From 847d5b4d1387a30f1798a5c3c59c3e0c31e00319 Mon Sep 17 00:00:00 2001 From: kennytm Date: Sun, 2 Feb 2020 02:29:28 +0800 Subject: Derive Clone + PartialEq + Eq for std::string::FromUtf8Error --- src/liballoc/string.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/liballoc/string.rs') diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 96f871d8897..8c9c95eec60 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -319,7 +319,7 @@ pub struct String { /// assert_eq!(vec![0, 159], value.unwrap_err().into_bytes()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -#[derive(Debug)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct FromUtf8Error { bytes: Vec, error: Utf8Error, -- cgit 1.4.1-3-g733a5 From fd2282388140ea0f370ee25c82f00be81c2f822c Mon Sep 17 00:00:00 2001 From: Trevor Spiteri Date: Sat, 1 Feb 2020 22:19:28 +0100 Subject: implement AsMut for String --- src/liballoc/string.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/liballoc/string.rs') diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 96f871d8897..99725917b5d 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2208,6 +2208,14 @@ impl AsRef for String { } } +#[stable(feature = "string_as_mut", since = "1.43.0")] +impl AsMut for String { + #[inline] + fn as_mut(&mut self) -> &mut str { + self + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<[u8]> for String { #[inline] -- cgit 1.4.1-3-g733a5 From 883e69db950522afb73fc9ad8ea122bacdd42ee4 Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Wed, 19 Feb 2020 16:37:58 -0500 Subject: Change FromStr for String to use Infallible directly Fixes the confusing documentation on `ParseError` by making it irrelevant. --- src/liballoc/string.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/liballoc/string.rs') diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 3cb1f259a0b..f5afea15d65 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2106,18 +2106,11 @@ impl ops::DerefMut for String { } } -/// An error when parsing a `String`. +/// A type alias for [`Infallible`]. /// -/// This `enum` is slightly awkward: it will never actually exist. This error is -/// part of the type signature of the implementation of [`FromStr`] on -/// [`String`]. The return type of [`from_str`], requires that an error be -/// defined, but, given that a [`String`] can always be made into a new -/// [`String`] without error, this type will never actually be returned. As -/// such, it is only here to satisfy said signature, and is useless otherwise. +/// This alias exists for backwards compatibility, and may be eventually deprecated. /// -/// [`FromStr`]: ../../std/str/trait.FromStr.html -/// [`String`]: struct.String.html -/// [`from_str`]: ../../std/str/trait.FromStr.html#tymethod.from_str +/// [`Infallible`]: ../../core/convert/enum.Infallible.html #[stable(feature = "str_parse_error", since = "1.5.0")] pub type ParseError = core::convert::Infallible; @@ -2125,7 +2118,7 @@ pub type ParseError = core::convert::Infallible; impl FromStr for String { type Err = core::convert::Infallible; #[inline] - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { Ok(String::from(s)) } } -- cgit 1.4.1-3-g733a5