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
#[macro_export]
macro_rules! rt_format_args {
(@[$spec:expr] [$($args:tt)*] $name:tt = $e:expr, $($rest:tt)*) => {
rt_format_args!(@[$spec] [$($args)* $crate::Param::named(stringify!($name), &$e),] $($rest)*)
};
(@[$spec:expr] [$($args:tt)*] $name:tt = $e:expr) => {
rt_format_args!(@[$spec] [$($args)* $crate::Param::named(stringify!($name), &$e),])
};
(@[$spec:expr] [$($args:tt)*] $e:expr, $($rest:tt)*) => {
rt_format_args!(@[$spec] [$($args)* $crate::Param::normal(&$e),] $($rest)*)
};
(@[$spec:expr] [$($args:tt)*] $e:expr) => {
rt_format_args!(@[$spec] [$($args)* $crate::Param::normal(&$e),])
};
(@[$spec:expr] [$($args:tt)*]) => {
$crate::FormatBuf::new(&$spec, &[$($args)*])
};
($spec:expr, $($rest:tt)*) => {
rt_format_args!(@[$spec] [] $($rest)*)
};
($spec:expr) => {
$crate::FormatBuf::new(&$spec, &[])
};
}
#[macro_export]
macro_rules! rt_format {
($($rest:tt)*) => {
rt_format_args!($($rest)*).map(|x| x.with(::std::fmt::format))
}
}
#[macro_export]
macro_rules! rt_print {
($($rest:tt)*) => {
rt_format_args!($($rest)*).map(|x| x.with($crate::_print))
}
}
#[macro_export]
macro_rules! rt_println {
($($rest:tt)*) => {
rt_format_args!($($rest)*).map(|mut x| x.newln().with($crate::_print))
}
}
#[macro_export]
macro_rules! rt_write {
($dest:expr, $($rest:tt)*) => {
rt_format_args!($($rest)*).and_then(|x|
x.with(|args| $dest.write_fmt(args)).map_err(::std::convert::From::from)
)
}
}
#[macro_export]
macro_rules! rt_writeln {
($dest:expr, $($rest:tt)*) => {
rt_format_args!($($rest)*).and_then(|mut x|
x.newln().with(|args| $dest.write_fmt(args)).map_err(::std::convert::From::from)
)
}
}