From f683bba4004cc07f9ac91d5d99a6bab76f335dba Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 30 Mar 2019 16:42:52 +0100 Subject: =?UTF-8?q?Create=20error=5Ftype!=20macro=20=E2=9C=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/export/pdf.rs | 53 +++++++++++++---------------------------------------- 1 file changed, 13 insertions(+), 40 deletions(-) (limited to 'src/export') diff --git a/src/export/pdf.rs b/src/export/pdf.rs index 31aa39d5..630a0501 100644 --- a/src/export/pdf.rs +++ b/src/export/pdf.rs @@ -1,14 +1,11 @@ //! Exporting into _PDF_ documents. use std::collections::HashSet; -use std::fmt::{self, Display, Debug, Formatter}; use std::io::{self, Write}; - use pdf::{PdfWriter, Ref, Rect, Version, Trailer, Content}; use pdf::doc::{Catalog, PageTree, Page, Resource, Text}; use pdf::font::{Type0Font, CIDFont, CIDFontType, CIDSystemInfo, FontDescriptor, FontFlags}; use pdf::font::{GlyphUnit, CMapEncoding, WidthRecord, FontStream, EmbeddedFontType}; - use crate::doc::{Document, Size, Text as DocText, TextCommand}; use crate::font::{Font, FontError}; @@ -284,9 +281,6 @@ impl std::ops::Deref for PdfFont { } } -/// Result type for _PDF_ creation. -type PdfResult = std::result::Result; - /// The error type for _PDF_ creation. pub enum PdfExportError { /// An error occured while subsetting the font for the _PDF_. @@ -295,38 +289,17 @@ pub enum PdfExportError { Io(io::Error), } -impl std::error::Error for PdfExportError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - PdfExportError::Font(err) => Some(err), - PdfExportError::Io(err) => Some(err), - } - } -} - -impl Display for PdfExportError { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - match self { - PdfExportError::Font(err) => write!(f, "font error: {}", err), - PdfExportError::Io(err) => write!(f, "io error: {}", err), - } - } -} - -impl Debug for PdfExportError { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - Display::fmt(self, f) - } -} - -impl From for PdfExportError { - fn from(err: io::Error) -> PdfExportError { - PdfExportError::Io(err) - } -} - -impl From for PdfExportError { - fn from(err: FontError) -> PdfExportError { - PdfExportError::Font(err) - } +error_type! { + err: PdfExportError, + res: PdfResult, + show: f => match err { + PdfExportError::Font(err) => write!(f, "font error: {}", err), + PdfExportError::Io(err) => write!(f, "io error: {}", err), + }, + source: match err { + PdfExportError::Font(err) => Some(err), + PdfExportError::Io(err) => Some(err), + }, + from: (io::Error, PdfExportError::Io(err)), + from: (FontError, PdfExportError::Font(err)), } -- cgit v1.2.3