backtrace

Struct Backtrace

Source
pub struct Backtrace { /* private fields */ }
Expand description

Representation of an owned and self-contained backtrace.

This structure can be used to capture a backtrace at various points in a program and later used to inspect what the backtrace was at that time.

Backtrace supports pretty-printing of backtraces through its Debug implementation.

§Required features

This function requires the std feature of the backtrace crate to be enabled, and the std feature is enabled by default.

Implementations§

Source§

impl Backtrace

Source

pub fn new() -> Backtrace

Captures a backtrace at the callsite of this function, returning an owned representation.

This function is useful for representing a backtrace as an object in Rust. This returned value can be sent across threads and printed elsewhere, and the purpose of this value is to be entirely self contained.

Note that on some platforms acquiring a full backtrace and resolving it can be extremely expensive. If the cost is too much for your application it’s recommended to instead use Backtrace::new_unresolved() which avoids the symbol resolution step (which typically takes the longest) and allows deferring that to a later date.

§Examples
use backtrace::Backtrace;

let current_backtrace = Backtrace::new();
§Required features

This function requires the std feature of the backtrace crate to be enabled, and the std feature is enabled by default.

Source

pub fn new_unresolved() -> Backtrace

Similar to new except that this does not resolve any symbols, this simply captures the backtrace as a list of addresses.

At a later time the resolve function can be called to resolve this backtrace’s symbols into readable names. This function exists because the resolution process can sometimes take a significant amount of time whereas any one backtrace may only be rarely printed.

§Examples
use backtrace::Backtrace;

let mut current_backtrace = Backtrace::new_unresolved();
println!("{current_backtrace:?}"); // no symbol names
current_backtrace.resolve();
println!("{current_backtrace:?}"); // symbol names now present
§Required features

This function requires the std feature of the backtrace crate to be enabled, and the std feature is enabled by default.

Source

pub fn frames(&self) -> &[BacktraceFrame]

Returns the frames from when this backtrace was captured.

The first entry of this slice is likely the function Backtrace::new, and the last frame is likely something about how this thread or the main function started.

§Required features

This function requires the std feature of the backtrace crate to be enabled, and the std feature is enabled by default.

Source

pub fn resolve(&mut self)

If this backtrace was created from new_unresolved then this function will resolve all addresses in the backtrace to their symbolic names.

If this backtrace has been previously resolved or was created through new, this function does nothing.

§Required features

This function requires the std feature of the backtrace crate to be enabled, and the std feature is enabled by default.

Trait Implementations§

Source§

impl Clone for Backtrace

Source§

fn clone(&self) -> Backtrace

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Backtrace

Source§

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

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

impl Default for Backtrace

Source§

fn default() -> Backtrace

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Backtrace

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Vec<BacktraceFrame>> for Backtrace

Source§

fn from(frames: Vec<BacktraceFrame>) -> Self

Converts to this type from the input type.
Source§

impl Into<Vec<BacktraceFrame>> for Backtrace

Source§

fn into(self) -> Vec<BacktraceFrame>

Converts this type into the (usually inferred) input type.
Source§

impl Serialize for Backtrace

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,