std: Stabilize FromStr and parse
This commits adds an associated type to the `FromStr` trait representing an error payload for parses which do not succeed. The previous return value, `Option<Self>` did not allow for this form of payload. After the associated type was added, the following attributes were applied: * `FromStr` is now stable * `FromStr::Err` is now stable * `FromStr::from_str` is now stable * `StrExt::parse` is now stable * `FromStr for bool` is now stable * `FromStr for $float` is now stable * `FromStr for $integral` is now stable * Errors returned from stable `FromStr` implementations are stable * Errors implement `Display` and `Error` (both impl blocks being `#[stable]`) Closes #15138
This commit is contained in:
parent
1a51eb9cca
commit
0cdde6e5e0
39 changed files with 389 additions and 260 deletions
|
@ -2127,7 +2127,7 @@ macro_rules! read_primitive {
|
|||
Json::F64(f) => Err(ExpectedError("Integer".to_string(), format!("{}", f))),
|
||||
// re: #12967.. a type w/ numeric keys (ie HashMap<uint, V> etc)
|
||||
// is going to have a string here, as per JSON spec.
|
||||
Json::String(s) => match s.parse() {
|
||||
Json::String(s) => match s.parse().ok() {
|
||||
Some(f) => Ok(f),
|
||||
None => Err(ExpectedError("Number".to_string(), s)),
|
||||
},
|
||||
|
@ -2165,7 +2165,7 @@ impl ::Decoder for Decoder {
|
|||
Json::String(s) => {
|
||||
// re: #12967.. a type w/ numeric keys (ie HashMap<uint, V> etc)
|
||||
// is going to have a string here, as per JSON spec.
|
||||
match s.parse() {
|
||||
match s.parse().ok() {
|
||||
Some(f) => Ok(f),
|
||||
None => Err(ExpectedError("Number".to_string(), s)),
|
||||
}
|
||||
|
@ -2597,8 +2597,9 @@ impl<'a, T: Encodable> fmt::Display for AsPrettyJson<'a, T> {
|
|||
}
|
||||
|
||||
impl FromStr for Json {
|
||||
fn from_str(s: &str) -> Option<Json> {
|
||||
from_str(s).ok()
|
||||
type Err = BuilderError;
|
||||
fn from_str(s: &str) -> Result<Json, BuilderError> {
|
||||
from_str(s)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue