Accept trailing comma in macros

This commit is contained in:
David Tolnay 2019-10-05 16:47:15 -04:00
parent f54adae5ef
commit 9e2e3c375f
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -22,6 +22,9 @@ macro_rules! bail {
($err:expr) => {
return std::result::Result::Err(std::convert::From::from($err));
};
($err:expr,) => {
$crate::bail!($err);
};
}
/// Construct an ad-hoc error from a string.
@ -31,6 +34,13 @@ macro_rules! bail {
/// `Debug` and `Display`.
#[macro_export]
macro_rules! anyhow {
($e:expr) => { $crate::Error::new_adhoc($e) };
($($arg:tt)*) => { $crate::Error::new_adhoc(format!($($arg)*)) };
($msg:expr) => {
$crate::Error::new_adhoc($msg)
};
($msg:expr,) => {
$crate::anyhow!($msg)
};
($fmt:expr, $($arg:tt)*) => {
$crate::Error::new_adhoc(format!($fmt, $($arg)*))
};
}