chiark / gitweb /
error_from_losedetails
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 12 Jul 2020 12:03:08 +0000 (13:03 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 12 Jul 2020 12:03:08 +0000 (13:03 +0100)
src/error.rs
src/pieces.rs

index e52953b5f1a778d043f1a34b639e1d2b141674aa..7d4431937a4a64ac67504d858caee478b1e7b4b5 100644 (file)
@@ -88,3 +88,13 @@ macro_rules! display_as_debug {
   }
 }
 pub use crate::display_as_debug;
+
+#[macro_export]
+macro_rules! error_from_losedetails {
+  {$to:ty, $variant:ident, $from:ty} => {
+    impl From<$from> for $to {
+      fn from(_: $from) -> Self { <$to>::$variant }
+    }
+  }
+}
+pub use crate::error_from_losedetails;
index 17e2acc27d3477ed818679545d8a939e2a411b50..42db5809b8e391124dfd7a1d7592730c2f2043cd 100644 (file)
@@ -23,9 +23,7 @@ pub enum SVGProcessError {
   WriteFail,
 }
 display_as_debug!{SVGProcessError}
-impl From<fmt::Error> for SVGProcessError {
-  fn from(_: fmt::Error) -> Self { SVGProcessError::WriteFail }
-}
+error_from_losedetails!{SVGProcessError, WriteFail, fmt::Error}
 
 #[throws(SVGProcessError)]
 pub fn svg_rescale_path(input: &str, scale: f64) -> String {