Function async_backtrace::backtrace

source ·
pub fn backtrace() -> Option<Box<[Location]>>
Expand description

Produces a backtrace starting at the currently-active frame (if any).

§Example

use async_backtrace::{framed, backtrace, Location};

#[tokio::main]
async fn main() {
    foo().await;
}

#[async_backtrace::framed]
async fn foo() {
    bar().await;
}

#[async_backtrace::framed]
async fn bar() {
    baz().await;
}

#[async_backtrace::framed]
async fn baz() {
    assert_eq!(&async_backtrace::backtrace().unwrap().iter().map(|l| l.to_string()).collect::<Vec<_>>()[..], &[
        "rust_out::baz::{{closure}} at src/lib.rs:19:1",
        "rust_out::bar::{{closure}} at src/lib.rs:14:1",
        "rust_out::foo::{{closure}} at src/lib.rs:9:1",
    ]);
}