cognitive_graphics/
errors.rs

1// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
2// the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/
3
4//! This module provides error enumerations.
5
6// -------------------------------------------------------------------------------------------------
7
8use std;
9use std::error::Error;
10
11// -------------------------------------------------------------------------------------------------
12
13/// Graphics errors.
14pub struct GraphicsError {
15    /// Description.
16    description: String,
17}
18
19// -------------------------------------------------------------------------------------------------
20
21impl GraphicsError {
22    /// Constructs new `GraphicsError` with description.
23    pub fn new(description: String) -> GraphicsError {
24        GraphicsError { description: description }
25    }
26}
27
28// -------------------------------------------------------------------------------------------------
29
30impl Error for GraphicsError {
31    fn description(&self) -> &str {
32        &self.description
33    }
34
35    fn cause(&self) -> Option<&Error> {
36        None
37    }
38}
39
40// -------------------------------------------------------------------------------------------------
41
42impl std::fmt::Debug for GraphicsError {
43    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
44        write!(f, "{}", self.description)
45    }
46}
47
48// -------------------------------------------------------------------------------------------------
49
50impl std::fmt::Display for GraphicsError {
51    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
52        write!(f, "{}", self.description)
53    }
54}
55
56// -------------------------------------------------------------------------------------------------