async-debug

Crates.ioasync-debug
lib.rsasync-debug
version0.1.3
sourcesrc
created_at2022-02-22 20:33:37.549216
updated_at2022-02-22 22:31:28.376954
descriptionDebug structs and enums containing values that require an async call to render
homepage
repositoryhttps://github.com/GothAck/rs-async-debug
max_upload_size
id537463
size6,579
Greg "GothAck" Miell (GothAck)

documentation

https://docs.rs/async-debug

README

Crates.io Crates.io docs.rs pre-commit

Async Debug

The async-debug crate makes it easy to debug structs and enums containing values that require an async call to render.

For example:

use tokio::sync::RwLock;

#[derive(Debug)]
struct MyStruct {
    my_value: RwLock<String>
}

let my_struct = MyStruct { my_value: RwLock::from("Hello, world!".to_string()) };
println!("{:?}", my_struct );

Prints something like:

MyStruct { my_value: RwLock { mr: 536870911, s: Semaphore { permits: 536870911 }, c: UnsafeCell { .. } } }

Along comes Async Debug

Just derive from async_debug::AsyncDebug and add the appropriate attribute!

Add to cargo.toml:

[dependencies]
async-debug = "0.1.3"
use async_debug::AsyncDebug;
use tokio::sync::RwLock;

#[derive(AsyncDebug)]
struct MyStruct {
    #[async_debug(async_call = RwLock::read, clone, ty = String)]
    my_value: RwLock<String>
}

let my_struct = MyStruct { my_value: RwLock::from("Hello, world!".to_string()) };
assert_eq!(
    format!("{:?}", my_struct.async_debug().await),
    "MyStruct { my_value: \"Hello, world!\" }",
);
Commit count: 61

cargo fmt