async_debug/lib.rs
1#![warn(rustdoc::missing_crate_level_docs)]
2#![warn(missing_docs)]
3
4//! # Async Debug
5//! The `async-debug` crate makes it easy to debug structs and enums containing
6//! values that require an async call to render.
7//!
8//! For example:
9//! ```rust
10//! use tokio::sync::RwLock;
11//!
12//! #[derive(Debug)]
13//! struct MyStruct {
14//! my_value: RwLock<String>
15//! }
16//!
17//! # fn main() {
18//! let my_struct = MyStruct { my_value: RwLock::from("Hello, world!".to_string()) };
19//! println!("{:?}", my_struct );
20//! # }
21//! ```
22//!
23//! Prints something like:
24//! ```text
25//! MyStruct { my_value: RwLock { mr: 536870911, s: Semaphore { permits: 536870911 }, c: UnsafeCell { .. } } }
26//! ```
27//!
28//! ## Along comes Async Debug
29//! Just derive from `async_debug::AsyncDebug` and add the appropriate attribute!
30//!
31//! Add to cargo.toml:
32//! ```toml
33//! [dependencies]
34//! async-debug = "0.1.3"
35//! ```
36//!
37//! ```rust
38//! use async_debug::AsyncDebug;
39//! use tokio::sync::RwLock;
40//!
41//! #[derive(AsyncDebug)]
42//! struct MyStruct {
43//! #[async_debug(async_call = RwLock::read, clone, ty = String)]
44//! my_value: RwLock<String>
45//! }
46//!
47//! # #[tokio::main]
48//! # async fn main() {
49//! let my_struct = MyStruct { my_value: RwLock::from("Hello, world!".to_string()) };
50//! assert_eq!(
51//! format!("{:?}", my_struct.async_debug().await),
52//! "MyStruct { my_value: \"Hello, world!\" }",
53//! );
54//! # }
55//! ```
56pub use async_debug_derive::AsyncDebug;
57
58/// `AsyncDebug` trait, this just marks the struct or enum as having AsyncDebug capabilities,
59/// the actual implementation is in an inherent impl
60pub trait AsyncDebug {}