1
Fork 0

Change FromStr for String to use Infallible directly

Fixes the confusing documentation on `ParseError` by making it
irrelevant.
This commit is contained in:
Peter Todd 2020-02-19 16:37:58 -05:00
parent 7d6b8c414e
commit 883e69db95
No known key found for this signature in database
GPG key ID: 2481403DA5F091FB

View file

@ -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 /// This alias exists for backwards compatibility, and may be eventually deprecated.
/// 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.
/// ///
/// [`FromStr`]: ../../std/str/trait.FromStr.html /// [`Infallible`]: ../../core/convert/enum.Infallible.html
/// [`String`]: struct.String.html
/// [`from_str`]: ../../std/str/trait.FromStr.html#tymethod.from_str
#[stable(feature = "str_parse_error", since = "1.5.0")] #[stable(feature = "str_parse_error", since = "1.5.0")]
pub type ParseError = core::convert::Infallible; pub type ParseError = core::convert::Infallible;
@ -2125,7 +2118,7 @@ pub type ParseError = core::convert::Infallible;
impl FromStr for String { impl FromStr for String {
type Err = core::convert::Infallible; type Err = core::convert::Infallible;
#[inline] #[inline]
fn from_str(s: &str) -> Result<String, ParseError> { fn from_str(s: &str) -> Result<String, Self::Err> {
Ok(String::from(s)) Ok(String::from(s))
} }
} }