Struct YoshiBacktrace

Source
pub struct YoshiBacktrace { /* private fields */ }
Available on crate feature std only.
Expand description

Performance-optimized backtrace wrapper with metadata.

This struct wraps std::backtrace::Backtrace (available with the std feature) and augments it with additional metadata such as capture timestamp, thread ID, thread name, and the performance cost of capturing the backtrace. It is designed for efficient debugging and performance analysis in production.

Implementations§

Source§

impl YoshiBacktrace

Source

pub fn new_captured() -> Self

Captures a new backtrace with performance monitoring.

This static method performs the actual capture of the backtrace, measures the time taken for the capture, and records thread information.

§Returns

A new YoshiBacktrace instance containing the captured backtrace and associated metadata.

§Examples
let bt = YoshiBacktrace::new_captured();
println!("Backtrace captured at {:?}", bt.capture_cost_nanos());
Source

pub fn status(&self) -> BacktraceStatus

Returns the status of the inner backtrace.

This method delegates to std::backtrace::Backtrace::status() to indicate whether the backtrace was successfully captured, disabled, or if some error occurred during capture.

§Returns

A std::backtrace::BacktraceStatus enum.

§Examples
let bt = YoshiBacktrace::new_captured();
match bt.status() {
    BacktraceStatus::Captured => println!("Backtrace captured successfully."),
    BacktraceStatus::Disabled => println!("Backtrace capture was disabled."),
    _ => println!("Backtrace status: {:?}", bt.status()),
}
Source

pub fn capture_cost_nanos(&self) -> Option<u64>

Gets the capture cost in nanoseconds.

This provides a metric for the performance overhead incurred when capturing the backtrace.

§Returns

An Option<u64> containing the capture cost in nanoseconds, or None if the cost was not measured (e.g., if backtrace capture was disabled).

§Examples
let bt = YoshiBacktrace::new_captured();
if let Some(cost) = bt.capture_cost_nanos() {
    println!("Backtrace capture took {} ns", cost);
}

Trait Implementations§

Source§

impl Debug for YoshiBacktrace

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for YoshiBacktrace

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the YoshiBacktrace for display, including metadata and the actual stack trace.

§Arguments
  • f - The formatter to write into.
§Returns

A fmt::Result indicating success or failure of the formatting.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.