1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Traits for working with `Error` in `std`-less environments.
//!
//! # Warning
//!
//! This is a pre-release meant to allow experimentation and integration into
//! the various error handling crates. Please do not use it yet! 1.0.0 is right
//! around the corner.
//!
//! # Usage
//!
//! This crate provides an [`Error`](trait.Error.html) trait which is identical
//! to [the one in std][std-error], except for not providing deprecated methods.
//!
//! This library also exposes two opt-in features:
//!
//! - `std`: simply re-export [`std::error::Error`][std-error].
//! - `alloc`: implement the [`Error`](trait.Error.html) trait on `alloc` errors
//!   (including boxed types).
//!
//! Libraries using this crate should forward their equivalent features to this
//! library.
//!
//! # Minimum Supported Rust Version (MSRV)
//!
//! With the default features, this crate works all the way down to 1.0.0. It
//! simply reexport libstd's `std::error` module.
//!
//! With `no-default-features`, the crate only compiles from 1.13.0 onwards
//! (see [#11] for more information on this limitation). It auto-detects the
//! Rust version in order to know which error structs to implement the trait on.
//!
//! [std-error]: https://doc.rust-lang.org/std/error/trait.Error.html
//! [#11]: https://github.com/core-error/core-error/issues/11

// If std feature is disabled, this crate is no_std.
// On 1.5.0 and under, no_std is unstable, so we can't just unconditionally use
// it.
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(unknown_lints)]
#![allow(bare_trait_objects)]

#[cfg(feature = "std")]
extern crate std as core;

#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "std")]
pub use std::error::*;

#[cfg(not(feature = "std"))]
mod error_trait;

/// Implementation of the not-yet-merged TypeInfo RFC, which is required for sound downcasting in
/// user crates.
#[doc(hidden)]
#[cfg(not(feature = "std"))]
pub mod typeinfo;

#[cfg(not(feature = "std"))]
pub use error_trait::*;