Repository: shepmaster/snafu (rust)

Issue:
Enhance `ensure` macro to allow trailing commas

Pull request:
Allow optional trailing commas in `ensure!`
Fixes #243

Patch:
diff --git a/src/lib.rs b/src/lib.rs
index 9ddf315..400b7dc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -196,7 +196,7 @@ pub use no_std_error::Error;
 /// ```
 #[macro_export]
 macro_rules! ensure {
-    ($predicate:expr, $context_selector:expr) => {
+    ($predicate:expr, $context_selector:expr $(,)*) => {
         if !$predicate {
             return $context_selector.fail().map_err(core::convert::Into::into);
         }


Test patch:
diff --git a/tests/ensure.rs b/tests/ensure.rs
new file mode 100644
index 0000000..5b643f6
--- /dev/null
+++ b/tests/ensure.rs
@@ -0,0 +1,22 @@
+use snafu::{ensure, Snafu};
+
+#[derive(Debug, Snafu)]
+enum Error {
+    AVeryLongVariantName { a_long_piece_of_information: i32 },
+}
+
+type Result<T, E = Error> = std::result::Result<T, E>;
+
+#[test]
+fn accepts_trailing_commas() {
+    fn example(a_long_piece_of_information: i32) -> Result<()> {
+        ensure!(
+            a_long_piece_of_information > a_long_piece_of_information - 1,
+            AVeryLongVariantName {
+                a_long_piece_of_information,
+            },
+        );
+        Ok(())
+    }
+    let _ = example(42);
+}