From e88fed53daf57320afc9ddb1a2e86b9e3ae73df2 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 12 Jul 2020 13:03:08 +0100 Subject: [PATCH] error_from_losedetails --- src/error.rs | 10 ++++++++++ src/pieces.rs | 4 +--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index e52953b5..7d443193 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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; diff --git a/src/pieces.rs b/src/pieces.rs index 17e2acc2..42db5809 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -23,9 +23,7 @@ pub enum SVGProcessError { WriteFail, } display_as_debug!{SVGProcessError} -impl From 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 { -- 2.30.2