diff --git a/.travis.yml b/.travis.yml index c771d1a..f311898 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,5 @@ cache: cargo script: - cargo test - cargo test --no-default-features +- cargo test --no-default-features --features std +- cargo test --no-default-features --features backtrace diff --git a/Cargo.toml b/Cargo.toml index 56e8df8..30256e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,8 +17,8 @@ optional = true version = "0.3.3" [features] -default = ["std", "derive"] -std = ["backtrace"] +default = ["std", "derive", "backtrace"] +std = [] derive = ["failure_derive"] [[example]] diff --git a/src/backtrace/mod.rs b/src/backtrace/mod.rs index a29e9a0..d24dfdf 100644 --- a/src/backtrace/mod.rs +++ b/src/backtrace/mod.rs @@ -1,6 +1,6 @@ use core::fmt::{self, Debug, Display}; -without_std! { +without_backtrace! { /// A `Backtrace`. /// /// This is an opaque wrapper around the backtrace provided by @@ -39,6 +39,16 @@ without_std! { pub fn new() -> Backtrace { Backtrace { _secret: () } } + + #[cfg(feature = "std")] + pub(crate) fn none() -> Backtrace { + Backtrace { _secret: () } + } + + #[cfg(feature = "std")] + pub(crate) fn is_none(&self) -> bool { + true + } } impl Default for Backtrace { @@ -60,7 +70,7 @@ without_std! { } } -with_std! { +with_backtrace! { extern crate backtrace; mod internal; diff --git a/src/lib.rs b/src/lib.rs index 3789585..91db97b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,12 @@ macro_rules! with_std { ($($i:item)*) => ($(#[cfg(feature = "std")]$i)*) } macro_rules! without_std { ($($i:item)*) => ($(#[cfg(not(feature = "std"))]$i)*) } +macro_rules! with_backtrace { + ($($i:item)*) => ($(#[cfg(all(feature = "backtrace", feature = "std"))]$i)*) +} +macro_rules! without_backtrace { + ($($i:item)*) => ($(#[cfg(any(not(feature = "backtrace"), not(feature = "std")))]$i)*) +} mod backtrace; mod compat;