1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
use std::error::Error; use std::fmt; pub type Result<T> = std::result::Result<T, PageError>; #[derive(Debug)] pub enum PageError { InvalidVersion, BadSegmentCount, MissingMagic, Io(std::io::Error), } impl fmt::Display for PageError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { PageError::InvalidVersion => { write!(f, "Invalid stream structure version (Should always be 0)") }, PageError::BadSegmentCount => write!(f, "Page has a segment count < 1"), PageError::MissingMagic => write!(f, "Page is missing a magic signature"), PageError::Io(..) => write!(f, "Encountered an std::io::Error"), } } } impl Error for PageError { fn source(&self) -> Option<&(dyn Error + 'static)> { match *self { PageError::Io(ref e) => Some(e), _ => None, } } } impl From<std::io::Error> for PageError { fn from(err: std::io::Error) -> PageError { PageError::Io(err) } }