Stabilize std::error
This commit is a first past stabilization of `std::error`: * The module is stable. * The `FromError` trait and impls are stable * The `Error` trait itself is left unstable, pending current APIs and possible revisions during the alpha cycle.
This commit is contained in:
parent
8efd9901b6
commit
7de9a73ab5
1 changed files with 8 additions and 0 deletions
|
@ -78,12 +78,15 @@
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
#![stable]
|
||||||
|
|
||||||
use prelude::v1::*;
|
use prelude::v1::*;
|
||||||
|
|
||||||
use str::Utf8Error;
|
use str::Utf8Error;
|
||||||
use string::{FromUtf8Error, FromUtf16Error};
|
use string::{FromUtf8Error, FromUtf16Error};
|
||||||
|
|
||||||
/// Base functionality for all errors in Rust.
|
/// Base functionality for all errors in Rust.
|
||||||
|
#[unstable = "the exact API of this trait may change"]
|
||||||
pub trait Error: Send {
|
pub trait Error: Send {
|
||||||
/// A short description of the error; usually a static string.
|
/// A short description of the error; usually a static string.
|
||||||
fn description(&self) -> &str;
|
fn description(&self) -> &str;
|
||||||
|
@ -96,18 +99,21 @@ pub trait Error: Send {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait for types that can be converted from a given error type `E`.
|
/// A trait for types that can be converted from a given error type `E`.
|
||||||
|
#[stable]
|
||||||
pub trait FromError<E> {
|
pub trait FromError<E> {
|
||||||
/// Perform the conversion.
|
/// Perform the conversion.
|
||||||
fn from_error(err: E) -> Self;
|
fn from_error(err: E) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any type is convertable from itself
|
// Any type is convertable from itself
|
||||||
|
#[stable]
|
||||||
impl<E> FromError<E> for E {
|
impl<E> FromError<E> for E {
|
||||||
fn from_error(err: E) -> E {
|
fn from_error(err: E) -> E {
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl Error for Utf8Error {
|
impl Error for Utf8Error {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -119,11 +125,13 @@ impl Error for Utf8Error {
|
||||||
fn detail(&self) -> Option<String> { Some(self.to_string()) }
|
fn detail(&self) -> Option<String> { Some(self.to_string()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl Error for FromUtf8Error {
|
impl Error for FromUtf8Error {
|
||||||
fn description(&self) -> &str { "invalid utf-8" }
|
fn description(&self) -> &str { "invalid utf-8" }
|
||||||
fn detail(&self) -> Option<String> { Some(self.to_string()) }
|
fn detail(&self) -> Option<String> { Some(self.to_string()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable]
|
||||||
impl Error for FromUtf16Error {
|
impl Error for FromUtf16Error {
|
||||||
fn description(&self) -> &str { "invalid utf-16" }
|
fn description(&self) -> &str { "invalid utf-16" }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue