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
#[macro_export]
macro_rules! decl_message_repr {
($vis:vis $ident:ident, $fallback:literal) => {
#[cfg(feature = "std")]
$vis struct $ident(Box<str>);
#[cfg(feature = "std")]
impl $ident {
$vis fn collect<T>(message: T) -> Self where T: core::fmt::Display {
Self(message.to_string().into())
}
}
#[cfg(feature = "std")]
impl core::fmt::Debug for $ident {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.0.fmt(f)
}
}
#[cfg(feature = "std")]
impl core::fmt::Display for $ident {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.0.fmt(f)
}
}
#[cfg(not(feature = "std"))]
$vis struct $ident;
#[cfg(not(feature = "std"))]
impl $ident {
$vis fn collect<T>(_: T) -> Self where T: core::fmt::Display {
Self
}
}
#[cfg(not(feature = "std"))]
impl core::fmt::Debug for $ident {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
$fallback.fmt(f)
}
}
#[cfg(not(feature = "std"))]
impl core::fmt::Display for $ident {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
$fallback.fmt(f)
}
}
}
}