1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use wasm_bindgen::JsValue;
pub trait DebugProps {
fn as_debug_props(&self) -> Option<JsValue>;
}
impl<T: DebugProps> DebugProps for &T {
fn as_debug_props(&self) -> Option<JsValue> {
DebugProps::as_debug_props(*self)
}
}
#[macro_export]
macro_rules! auto_debug_props {
($v:expr) => {{
#[allow(unused_imports)]
use ::core::fmt::Debug;
#[allow(unused_imports)]
use $crate::{impl_auto_debug_props::*, DebugProps};
match $v {
ref v => match v
.is_debug_props_or_not()
.intermediate_value_to_debug_props(v)
{
tag_or_v => tag_or_v.is_impl_debug_or_not().output_debug_props(v),
},
}
}};
}
pub mod impl_auto_debug_props {
use wasm_bindgen::JsValue;
fn debug_props<T: super::DebugProps>(v: &T) -> Option<JsValue> {
v.as_debug_props()
}
fn debug_debug<T: ::core::fmt::Debug>(v: &T) -> Option<JsValue> {
Some(JsValue::from(format!("{:#?}", v)))
}
fn debug_any<T>(_: &T) -> Option<JsValue> {
let ty = std::any::type_name::<T>();
Some(JsValue::from(format!("{} {{ ... }}", ty)))
}
pub trait IsDebugPropsOrNot {
type Output;
fn is_debug_props_or_not(&self) -> Self::Output;
}
pub struct IsDebugPropsTag;
impl IsDebugPropsTag {
#[inline]
pub fn intermediate_value_to_debug_props<T>(self, _: &T) -> Self {
self
}
#[inline]
pub fn is_impl_debug_or_not(self) -> Self {
self
}
#[inline]
pub fn output_debug_props<T: super::DebugProps>(self, v: &T) -> Option<JsValue> {
debug_props(v)
}
}
pub struct NotImplTag;
impl NotImplTag {
#[inline]
pub fn intermediate_value_to_debug_props<T>(self, v: &T) -> &T {
v
}
#[inline]
pub fn output_debug_props<T>(self, v: &T) -> Option<JsValue> {
debug_any(v)
}
}
pub trait IsDebugProps {
#[inline]
fn is_debug_props_or_not(&self) -> IsDebugPropsTag {
IsDebugPropsTag
}
}
impl<T: super::DebugProps> IsDebugProps for T {}
pub trait NotImpl {
#[inline]
fn is_debug_props_or_not(&self) -> NotImplTag {
NotImplTag
}
#[inline]
fn is_impl_debug_or_not(&self) -> NotImplTag {
NotImplTag
}
}
impl<T> NotImpl for &T {}
pub struct IsImplDebugTag;
impl IsImplDebugTag {
#[inline]
pub fn output_debug_props<T: ::core::fmt::Debug>(self, v: &T) -> Option<JsValue> {
debug_debug(v)
}
}
pub trait IsImplDebug {
#[inline]
fn is_impl_debug_or_not(&self) -> IsImplDebugTag {
IsImplDebugTag
}
}
impl<T: ::core::fmt::Debug> IsImplDebug for T {}
}