From 2f175f59b033ebe74f86e08becb2bc1e759bdeee Mon Sep 17 00:00:00 2001 From: Jake Sandler Date: Sat, 9 Jun 2018 10:36:04 -0400 Subject: added std::error::Error Implmentations --- src/lib.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index b3d925a..258b3fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,8 @@ extern crate lopdf; #[macro_use] extern crate bitflags; +#[macro_use] +extern crate derive_error; use lopdf::{Document, ObjectId, Object, StringFormat}; use std::path::Path; @@ -67,29 +69,33 @@ pub enum FieldState { Text { text: String } } -#[derive(Debug)] +#[derive(Debug, Error)] /// Errors that may occur while loading a PDF pub enum LoadError { + /// An IO Error IoError(io::Error), + /// A dictionary key that must be present in order to find forms was not present DictionaryKeyNotFound, + /// The reference `ObjectId` did not point to any values + #[error(non_std, no_from)] NoSuchReference(ObjectId), + /// An element that was expected to be a reference was not a reference NotAReference, + /// A value that must be a certain type was not that type UnexpectedType } /// Errors That may occur while setting values in a form +#[derive(Debug, Error)] pub enum ValueError { + /// The method used to set the state is incompatible with the type of the field TypeMismatch, + /// One or more selected values are not valid choices InvalidSelection, + /// Multiple values were selected when only one was allowed TooManySelected } -impl From for LoadError { - fn from(error: io::Error) -> Self { - LoadError::IoError(error) - } -} - trait PdfObjectDeref { fn deref<'a>(&self, doc: &'a Document) -> Result<&'a Object, LoadError>; } -- cgit v1.2.3