const_panic/fmt_impls/
option_fmt_impls.rs1use crate::{FmtArg, PanicFmt, PanicVal};
2
3impl<T> PanicFmt for Option<T>
7where
8 T: PanicFmt,
9{
10 type This = Self;
11 type Kind = crate::fmt::IsStdType;
12 const PV_COUNT: usize = 4 + T::PV_COUNT;
13}
14
15macro_rules! impl_for_option {
16 (
17 $((for[$($generics:tt)*],$lt:lifetime, $ty:ty, $unref:ty))*
18 ) => (
19 $(
20 impl<'s, $($generics)*> crate::StdWrapper<&'s Option<$ty>> {
21 #[doc = concat!(
22 "Converts this `Option<",
23 stringify!($ty),
24 ">` to a `PanicVal` array."
25 )]
26 pub const fn to_panicvals(
27 self: Self,
28 mut fmtarg: FmtArg,
29 ) -> [PanicVal<$lt>; 5] {
30 use crate::{PanicVal, StdWrapper, __::EPV, fmt};
31
32 match self.0 {
33 Some(x) => [
34 PanicVal::write_str("Some"),
35 {fmtarg = fmtarg.indent(); fmt::OpenParen.to_panicval(fmtarg)},
36 StdWrapper::<&$unref>(x).to_panicval(fmtarg),
37 fmt::COMMA_TERM.to_panicval(fmtarg),
38 {fmtarg = fmtarg.unindent(); fmt::CloseParen.to_panicval(fmtarg)},
39 ],
40 None => [PanicVal::write_str("None"), EPV, EPV, EPV, EPV],
41 }
42 }
43 }
44 )*
45 )
46}
47
48macro_rules! impl_for_option_outer {
49 (
50 $(($lt:lifetime, $ty:ty, $unref:ty))*
51 ) => (
52 impl_for_option!{
53 $(
54 (for[], $lt, $ty, $unref)
55 (for[const N: usize], 's, [$ty; N], [$ty; N])
56 (for[const N: usize], 's, &'s [$ty; N], [$ty; N])
57 (for[], 's, &'s [$ty], [$ty])
58 )*
59 }
60 )
61}
62
63impl_for_option_outer! {
64 ('static, bool, bool)
65 ('static, u8, u8)
66 ('static, u16, u16)
67 ('static, u32, u32)
68 ('static, u64, u64)
69 ('static, u128, u128)
70 ('static, i8, i8)
71 ('static, i16, i16)
72 ('static, i32, i32)
73 ('static, i64, i64)
74 ('static, i128, i128)
75 ('static, isize, isize)
76 ('static, usize, usize)
77 ('s, &'s str, str)
78}