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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#[macro_export]
macro_rules! template {
($($tt:tt)*) => {
$crate::_template1_!{"",; $($tt)*}
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! _template1_ {
($fmt:expr, $($args:expr,)*; $text:literal $($tail:tt)*) => {
$crate::_template1_!{concat!($fmt, $text), $($args,)*; $($tail)*}
};
($fmt:expr, $($args:expr,)*; {$e:expr} $($tail:tt)*) => {
$crate::_template1_!{concat!($fmt, "{}"), $($args,)* $e,; $($tail)*}
};
($fmt:expr, $($args:expr,)*; {$e:expr;$($s:tt)*} $($tail:tt)*) => {
$crate::_template1_!{concat!($fmt, "{:", $(stringify!($s),)* "}"), $($args,)* $e,; $($tail)*}
};
($fmt:expr, $($args:expr,)*; |$f:ident| { $($body:tt)* } $($tail:tt)*) => {
$crate::_template1_!{concat!($fmt, "{}"), $($args,)* $crate::FnFmt(|$f| { $($body)* }),; $($tail)*}
};
($fmt:expr, $($args:expr,)*; let $p:pat = $e:expr; $($tail:tt)*) => {
$crate::_template1_!(concat!($fmt, "{}"), $($args,)* $crate::FnFmt(|f| match $e { $p => f.write_fmt($crate::template!{$($tail)*}) }),;)
};
($fmt:expr, $($args:expr,)*; if ($e:expr) { $($body:tt)* } $($tail:tt)*) => {
$crate::_template2_!($fmt, $($args,)*; f [[if ($e) { f.write_fmt($crate::template!{$($body)*}) }]]; $($tail)*)
};
($fmt:expr, $($args:expr,)*; if let $p:pat = ($e:expr) { $($body:tt)* } $($tail:tt)*) => {
$crate::_template2_!($fmt, $($args,)*; f [[if let $p = ($e) { f.write_fmt($crate::template!{$($body)*}) }]]; $($tail)*)
};
($fmt:expr, $($args:expr,)*; match ($e:expr) { $($p:pat => { $($body:tt)* })* } $($tail:tt)*) => {
$crate::_template1_!(concat!($fmt, "{}"), $($args,)* $crate::FnFmt(|f| match $e { $($p => f.write_fmt($crate::template!{$($body)*}),)* }),; $($tail)*)
};
($fmt:expr, $($args:expr,)*; for $p:pat in ($e:expr) { $($body:tt)* } $($tail:tt)*) => {
$crate::_template1_!(concat!($fmt, "{}"), $($args,)* $crate::FnFmt(|f| { for $p in $e { f.write_fmt($crate::template!{$($body)*})?; } Ok(()) }),; $($tail)*)
};
($fmt:expr, $($args:expr,)*;) => {
format_args!($fmt $(,$args)*)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! _template2_ {
($fmt:expr, $($args:expr,)*; $f:ident [$($c:tt)*]; else if ($e:expr) { $($body:tt)* } $($tail:tt)*) => {
$crate::_template2_!($fmt, $($args,)*; $f [$($c)* [else if ($e) { $f.write_fmt($crate::template!{$($body)*}) }]]; $($tail)*)
};
($fmt:expr, $($args:expr,)*; $f:ident [$($c:tt)*]; else if let $p:pat = ($e:expr) { $($body:tt)* } $($tail:tt)*) => {
$crate::_template2_!($fmt, $($args,)*; $f [$($c)* [else if let $p = ($e) { $f.write_fmt($crate::template!{$($body)*}) }]]; $($tail)*)
};
($fmt:expr, $($args:expr,)*; $f:ident [$([$($c:tt)*])*]; else { $($body:tt)* } $($tail:tt)*) => {
$crate::_template1_!(concat!($fmt, "{}"), $($args,)* $crate::FnFmt(|$f| $($($c)*)* else { $f.write_fmt($crate::template!{$($body)*}) }),; $($tail)*)
};
($fmt:expr, $($args:expr,)*; $f:ident [$([$($c:tt)*])*]; $($tail:tt)*) => {
$crate::_template1_!(concat!($fmt, "{}"), $($args,)* $crate::FnFmt(|$f| $($($c)*)* else { Ok(()) }),; $($tail)*)
};
}