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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2016, The Gtk-rs Project Developers.
// See the COPYRIGHT file at the top-level directory of this distribution.
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>

use std::error::Error;
use std::fmt;
use std::io;
use ffi::enums::Status;

#[derive(Debug)]
pub enum BorrowError {
    Cairo(Status),
    NonExclusive,
}

impl From<Status> for BorrowError {
    fn from(status: Status) -> Self {
        BorrowError::Cairo(status)
    }
}

impl fmt::Display for BorrowError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            BorrowError::Cairo(status) => write!(f, "BorrowError::Cairo({:?})", status),
            BorrowError::NonExclusive  => write!(f, "BorrowError::NonExclusive" ),
        }
    }
}

impl Error for BorrowError {
    fn description(&self) -> &str {
        match *self {
            BorrowError::Cairo(_) => "BorrowError::Cairo",
            BorrowError::NonExclusive => "BorrowError::NonExclusive",
        }
    }

    fn cause(&self) -> Option<&Error> {
        None
    }
}

#[derive(Debug)]
pub enum IoError {
    Cairo(Status),
    Io(io::Error),
}

impl From<Status> for IoError {
    fn from(status: Status) -> Self {
        IoError::Cairo(status)
    }
}

impl fmt::Display for IoError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            IoError::Cairo(status) => write!(f, "IoError::Cairo({:?})", status),
            IoError::Io(ref e) => write!(f, "IoError::Io({})", e),
        }
    }
}

impl Error for IoError {
    fn description(&self) -> &str {
        match *self {
            IoError::Cairo(_) => "IoError::Cairo",
            IoError::Io(ref e) => e.description(),
        }
    }

    fn cause(&self) -> Option<&Error> {
        match *self {
            IoError::Cairo(_) => None,
            IoError::Io(ref e) => Some(e),
        }
    }
}