Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 84c305e

Browse files
carols10centsdavidbarsky
authored andcommitted
Add an is_empty method to Backtrace (#297)
1 parent 7cec324 commit 84c305e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

failure_derive/tests/wraps.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ fn wrap_backtrace_error() {
5858
.and_then(|err| err.downcast_ref::<io::Error>())
5959
.is_some());
6060
assert!(err.backtrace().is_some());
61+
assert!(err.backtrace().is_empty());
62+
assert_eq!(err.backtrace().is_empty(), err.backtrace().to_string().trim().is_empty());
6163
}
6264

6365
#[derive(Fail, Debug)]
@@ -91,4 +93,6 @@ fn wrap_enum_error() {
9193
.and_then(|err| err.downcast_ref::<fmt::Error>())
9294
.is_some());
9395
assert!(err.backtrace().is_some());
96+
assert!(err.backtrace().is_empty());
97+
assert_eq!(err.backtrace().is_empty(), err.backtrace().to_string().trim().is_empty());
9498
}

src/backtrace/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ without_backtrace! {
5252
pub(crate) fn is_none(&self) -> bool {
5353
true
5454
}
55+
56+
/// Returns true if displaying this backtrace would be an empty string.
57+
///
58+
/// > (We have detected that this crate was documented with no_std
59+
/// > compatibility turned on. The version of this crate that has been
60+
/// > documented here will never generate a backtrace and this method
61+
/// > will always return true.)
62+
pub fn is_empty(&self) -> bool {
63+
true
64+
}
5565
}
5666

5767
impl Default for Backtrace {
@@ -118,6 +128,11 @@ with_backtrace! {
118128
pub(crate) fn is_none(&self) -> bool {
119129
self.internal.is_none()
120130
}
131+
132+
/// Returns true if displaying this backtrace would be an empty string.
133+
pub fn is_empty(&self) -> bool {
134+
self.internal.is_none()
135+
}
121136
}
122137

123138
impl Default for Backtrace {

0 commit comments

Comments
 (0)