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
use std::{error, fmt};
/// Result type alias used by this library.
pub type Result<T> = std::result::Result<T, Error>;
/// Errors that can be created by this library.
#[derive(Debug)]
pub enum Error {
/// Shader compilation error.
///
/// String contains error message returned by OpenGL shader compiler.
CompileShader(String),
/// Program linking error.
///
/// String contains error message returned by OpenGL shader program linker.
LinkProgram(String),
/// Out of bounds error.
///
/// This error is formed when x ∉ [0; width), y ∉ [0; height).
OutOfBounds {
/// (width, height) of indexable area. Lower bound is implied to be (0, 0).
upper_bound: (usize, usize),
/// (x, y) that are out of bounds.
indices: (usize, usize),
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::CompileShader(ref info) => info.fmt(f),
Error::LinkProgram(ref info) => info.fmt(f),
Error::OutOfBounds { upper_bound, indices } => {
let (w, h) = upper_bound;
write!(f, "access at {:?} is out of bounds ([0; {}), [0; {}))", indices, w, h)
},
}
}
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
Error::CompileShader(_) => None,
Error::LinkProgram(_) => None,
Error::OutOfBounds { .. } => None,
}
}
}