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
use std::{error, fmt};
#[derive(Debug, Clone)]
pub enum AddressbookError {
IO(String),
InvalidAddress(String),
}
impl fmt::Display for AddressbookError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
AddressbookError::IO(ref str) => write!(f, "IO error: {}", str),
AddressbookError::InvalidAddress(ref str) => write!(f, "Invalid address: {}", str),
}
}
}
impl error::Error for AddressbookError {
fn description(&self) -> &str {
"Addressbook error"
}
fn cause(&self) -> Option<&error::Error> {
match *self {
_ => None,
}
}
}