From: Ian Jackson Date: Sun, 12 Jul 2020 12:03:08 +0000 (+0100) Subject: error_from_losedetails X-Git-Tag: otter-0.2.0~1363 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e88fed53daf57320afc9ddb1a2e86b9e3ae73df2;p=otter.git error_from_losedetails --- 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 {