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
extern crate core;
extern crate glium;
extern crate std;
use std::error::Error;
#[derive(Debug, Copy, Clone)]
pub enum ShapeCreationError {
VertexBufferCreationError(glium::vertex::BufferCreationError),
NotEnoughDivisionsInU,
NotEnoughDivisionsInV,
}
impl std::error::Error for ShapeCreationError {
fn description(&self) -> &str {
match &self {
ShapeCreationError::VertexBufferCreationError(ref err) => err.description(),
ShapeCreationError::NotEnoughDivisionsInU => "Not enough divisions in the u axis",
ShapeCreationError::NotEnoughDivisionsInV => "Not enough divisions in the v axis",
}
}
fn cause(&self) -> Option<&dyn Error> {
match &self {
ShapeCreationError::VertexBufferCreationError(ref error) => Some(error),
_ => None,
}
}
}
impl From<glium::vertex::BufferCreationError> for ShapeCreationError {
fn from(error: glium::vertex::BufferCreationError) -> Self {
ShapeCreationError::VertexBufferCreationError(error)
}
}
impl core::fmt::Display for ShapeCreationError {
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(fmt, "{}", self.description())
}
}