#[macro_export]
macro_rules! formatx {
($($args:tt)*) => {
$crate::_formatx_impl!(finish, $($args)*)
};
}
#[macro_export]
macro_rules! formatxl {
($($args:tt)*) => {
$crate::_formatx_impl!(finish_lenient, $($args)*)
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! _formatx_impl {
($finish:ident, $template:expr $(,)?) => {
(|| {
$crate::Template::new($template)?.render().$finish()
})()
};
($finish:ident, $template:expr, $($args:tt)*) => {
(|| {
let t = $crate::Template::new($template)?;
let mut r = t.render();
$crate::_formatx_impl!(@arg r, $($args)*);
r.$finish()
})()
};
(@arg $r:expr, $name:ident = $value:expr $(,)?) => {
$r.named(stringify!($name), &$value);
};
(@arg $r:expr, $value:expr $(,)?) => {
$r.arg(&$value);
};
(@arg $r:expr, $name:ident = $value:expr, $($rest:tt)*) => {
$r.named(stringify!($name), &$value);
$crate::_formatx_impl!(@arg $r, $($rest)*);
};
(@arg $r:expr, $value:expr, $($rest:tt)*) => {
$r.arg(&$value);
$crate::_formatx_impl!(@arg $r, $($rest)*);
};
}