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
use crate::{FmtArg, PanicFmt, PanicVal};
impl<T> PanicFmt for Option<T>
where
T: PanicFmt,
{
type This = Self;
type Kind = crate::fmt::IsStdType;
const PV_COUNT: usize = 4 + T::PV_COUNT;
}
macro_rules! impl_for_option {
(
$((for[$($generics:tt)*],$lt:lifetime, $ty:ty, $unref:ty))*
) => (
$(
impl<'s, $($generics)*> crate::StdWrapper<&'s Option<$ty>> {
#[doc = concat!(
"Converts this `Option<",
stringify!($ty),
">` to a `PanicVal` array."
)]
pub const fn to_panicvals(
self: Self,
mut fmtarg: FmtArg,
) -> [PanicVal<$lt>; 5] {
use crate::{PanicVal, StdWrapper, __::EPV, fmt};
match self.0 {
Some(x) => [
PanicVal::write_str("Some"),
{fmtarg = fmtarg.indent(); fmt::OpenParen.to_panicval(fmtarg)},
StdWrapper::<&$unref>(x).to_panicval(fmtarg),
fmt::COMMA_TERM.to_panicval(fmtarg),
{fmtarg = fmtarg.unindent(); fmt::CloseParen.to_panicval(fmtarg)},
],
None => [PanicVal::write_str("None"), EPV, EPV, EPV, EPV],
}
}
}
)*
)
}
macro_rules! impl_for_option_outer {
(
$(($lt:lifetime, $ty:ty, $unref:ty))*
) => (
impl_for_option!{
$(
(for[], $lt, $ty, $unref)
(for[const N: usize], 's, [$ty; N], [$ty; N])
(for[const N: usize], 's, &'s [$ty; N], [$ty; N])
(for[], 's, &'s [$ty], [$ty])
)*
}
)
}
impl_for_option_outer! {
('static, bool, bool)
('static, u8, u8)
('static, u16, u16)
('static, u32, u32)
('static, u64, u64)
('static, u128, u128)
('static, i8, i8)
('static, i16, i16)
('static, i32, i32)
('static, i64, i64)
('static, i128, i128)
('static, isize, isize)
('static, usize, usize)
('s, &'s str, str)
}