inc_complete/db/
debug_with_db.rs1use crate::Db;
2
3pub trait DebugWithDb<Storage>: Sized {
8 fn debug_with_db<'a>(&'a self, db: &'a Db<Storage>) -> DebugWithDbWrapper<'a, Self, Storage> {
9 DebugWithDbWrapper { obj: self, db }
10 }
11
12 fn fmt_with_db(&self, _db: &Db<Storage>, f: &mut std::fmt::Formatter) -> std::fmt::Result;
13}
14
15pub fn debug_with_db<'a, T, Storage>(
16 obj: &'a T,
17 db: &'a Db<Storage>,
18) -> DebugWithDbWrapper<'a, T, Storage> {
19 DebugWithDbWrapper { obj, db }
20}
21
22pub struct DebugWithDbWrapper<'a, T, S> {
24 obj: &'a T,
25 db: &'a Db<S>,
26}
27
28impl<T, S> std::fmt::Debug for DebugWithDbWrapper<'_, T, S>
29where
30 T: DebugWithDb<S>,
31{
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 self.obj.fmt_with_db(self.db, f)
34 }
35}
36
37impl<T: std::fmt::Debug, S> DebugWithDb<S> for T {
38 fn fmt_with_db(&self, _db: &Db<S>, f: &mut std::fmt::Formatter) -> std::fmt::Result {
39 write!(f, "{self:?}")
40 }
41}