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

Commit

Permalink
Add an is_empty method to Backtrace (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents authored and davidbarsky committed Jan 22, 2019
1 parent 7cec324 commit 84c305e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions failure_derive/tests/wraps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ fn wrap_backtrace_error() {
.and_then(|err| err.downcast_ref::<io::Error>())
.is_some());
assert!(err.backtrace().is_some());
assert!(err.backtrace().is_empty());
assert_eq!(err.backtrace().is_empty(), err.backtrace().to_string().trim().is_empty());
}

#[derive(Fail, Debug)]
Expand Down Expand Up @@ -91,4 +93,6 @@ fn wrap_enum_error() {
.and_then(|err| err.downcast_ref::<fmt::Error>())
.is_some());
assert!(err.backtrace().is_some());
assert!(err.backtrace().is_empty());
assert_eq!(err.backtrace().is_empty(), err.backtrace().to_string().trim().is_empty());
}
15 changes: 15 additions & 0 deletions src/backtrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ without_backtrace! {
pub(crate) fn is_none(&self) -> bool {
true
}

/// Returns true if displaying this backtrace would be an empty string.
///
/// > (We have detected that this crate was documented with no_std
/// > compatibility turned on. The version of this crate that has been
/// > documented here will never generate a backtrace and this method
/// > will always return true.)
pub fn is_empty(&self) -> bool {
true
}
}

impl Default for Backtrace {
Expand Down Expand Up @@ -118,6 +128,11 @@ with_backtrace! {
pub(crate) fn is_none(&self) -> bool {
self.internal.is_none()
}

/// Returns true if displaying this backtrace would be an empty string.
pub fn is_empty(&self) -> bool {
self.internal.is_none()
}
}

impl Default for Backtrace {
Expand Down

0 comments on commit 84c305e

Please sign in to comment.