cairo/
error.rs

1// Copyright 2016, The Gtk-rs Project Developers.
2// See the COPYRIGHT file at the top-level directory of this distribution.
3// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
4
5use enums::Status;
6use std::error::Error;
7use std::fmt;
8use std::io;
9
10#[derive(Debug)]
11pub enum BorrowError {
12    Cairo(Status),
13    NonExclusive,
14}
15
16impl From<Status> for BorrowError {
17    fn from(status: Status) -> Self {
18        BorrowError::Cairo(status)
19    }
20}
21
22impl fmt::Display for BorrowError {
23    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24        match *self {
25            BorrowError::Cairo(status) => write!(f, "BorrowError::Cairo({})", status),
26            BorrowError::NonExclusive => write!(f, "BorrowError::NonExclusive"),
27        }
28    }
29}
30
31impl Error for BorrowError {
32    fn description(&self) -> &str {
33        match *self {
34            BorrowError::Cairo(_) => "BorrowError::Cairo",
35            BorrowError::NonExclusive => "BorrowError::NonExclusive",
36        }
37    }
38
39    fn cause(&self) -> Option<&dyn Error> {
40        None
41    }
42}
43
44#[derive(Debug)]
45pub enum IoError {
46    Cairo(Status),
47    Io(io::Error),
48}
49
50impl From<Status> for IoError {
51    fn from(status: Status) -> Self {
52        IoError::Cairo(status)
53    }
54}
55
56impl fmt::Display for IoError {
57    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58        match *self {
59            IoError::Cairo(status) => write!(f, "IoError::Cairo({})", status),
60            IoError::Io(ref e) => write!(f, "IoError::Io({})", e),
61        }
62    }
63}
64
65impl Error for IoError {
66    fn description(&self) -> &str {
67        match *self {
68            IoError::Cairo(_) => "IoError::Cairo",
69            IoError::Io(ref e) => e.description(),
70        }
71    }
72
73    fn cause(&self) -> Option<&dyn Error> {
74        match *self {
75            IoError::Cairo(_) => None,
76            IoError::Io(ref e) => Some(e),
77        }
78    }
79}