Implement std::error::Error for renderer errors

This commit is contained in:
Joonas Javanainen 2019-07-12 20:29:00 +03:00
parent a2d3e434af
commit 930d44e92b
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179
3 changed files with 44 additions and 0 deletions

View File

@ -7,6 +7,7 @@
- Redesigned window API
- Redesigned progress bar API
- Redesigned color editor/picker API
- Renderer errors implement std::error::Error
### Removed

View File

@ -7,6 +7,8 @@ use gfx::traits::FactoryExt;
use gfx::{CommandBuffer, Encoder, Factory, IntoIndexBuffer, Rect, Resources, Slice};
use imgui::internal::RawWrapper;
use imgui::{DrawCmd, DrawCmdParams, DrawData, DrawIdx, DrawVert, ImString, TextureId, Textures};
use std::error::Error;
use std::fmt;
use std::usize;
#[derive(Clone, Debug)]
@ -18,6 +20,32 @@ pub enum RendererError {
BadTexture(TextureId),
}
impl fmt::Display for RendererError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::RendererError::*;
match *self {
Update(ref e) => write!(f, "{}", e),
Buffer(ref e) => write!(f, "{}", e),
Pipeline(ref e) => write!(f, "{}", e),
Combined(ref e) => write!(f, "{}", e),
BadTexture(ref t) => write!(f, "Bad texture ID: {}", t.id()),
}
}
}
impl Error for RendererError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
use self::RendererError::*;
match *self {
Update(ref e) => Some(e),
Buffer(ref e) => Some(e),
Pipeline(ref e) => Some(e),
Combined(ref e) => Some(e),
BadTexture(_) => None,
}
}
}
impl From<gfx::UpdateError<usize>> for RendererError {
fn from(e: gfx::UpdateError<usize>) -> RendererError {
RendererError::Update(e)

View File

@ -10,6 +10,7 @@ use glium::{
use imgui::internal::RawWrapper;
use imgui::{DrawCmd, DrawCmdParams, DrawData, ImString, TextureId, Textures};
use std::borrow::Cow;
use std::error::Error;
use std::fmt;
use std::rc::Rc;
use std::usize;
@ -24,6 +25,20 @@ pub enum RendererError {
BadTexture(TextureId),
}
impl Error for RendererError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
use self::RendererError::*;
match *self {
Vertex(ref e) => Some(e),
Index(ref e) => Some(e),
Program(ref e) => Some(e),
Texture(ref e) => Some(e),
Draw(ref e) => Some(e),
BadTexture(_) => None,
}
}
}
impl fmt::Display for RendererError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::RendererError::*;