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

feat(handler): add methods to mutate and remove backtrace/spantrace #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,37 @@ impl Handler {
self.backtrace.as_ref()
}

/// Return a mutable reference to the captured `Backtrace` type
pub fn backtrace_mut(&mut self) -> Option<&mut Backtrace> {
self.backtrace.as_mut()
}

/// Remove the captured `Backtrace` if present.
pub fn clear_backtrace(&mut self) {
self.backtrace = None;
}
Comment on lines +25 to +33
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially tried to use the .backtrace_mut() as in #130 (comment) , and it didn't work as it returns Option<&mut Backtrace> rather than &mut Option<Backtrace>.

I think that's more idiomatic rust, and so having two methods makes sense, but if you'd rather we delete clear_backtrace() and change the signature of backtrace_mut to:

pub fn backtrace_mut(&mut self) -> &mut Option<Backtrace> {

that works for me too.


/// Return a reference to the captured `SpanTrace` type
#[cfg(feature = "capture-spantrace")]
#[cfg_attr(docsrs, doc(cfg(feature = "capture-spantrace")))]
pub fn span_trace(&self) -> Option<&SpanTrace> {
self.span_trace.as_ref()
}

/// Return a mutable reference to the captured `SpanTrace` type
#[cfg(feature = "capture-spantrace")]
#[cfg_attr(docsrs, doc(cfg(feature = "capture-spantrace")))]
pub fn span_trace_mut(&mut self) -> Option<&mut SpanTrace> {
self.span_trace.as_mut()
}

/// Remove the captured `SpanTrace` if present.
#[cfg(feature = "capture-spantrace")]
#[cfg_attr(docsrs, doc(cfg(feature = "capture-spantrace")))]
pub fn clear_span_trace(&mut self) {
self.span_trace = None;
}

pub(crate) fn format_backtrace<'a>(
&'a self,
trace: &'a backtrace::Backtrace,
Expand Down