use std::{
error,
fmt::{self, Display, Formatter},
};
#[derive(Debug)]
pub enum Error {
InvalidTextureSize {
width: u32,
height: u32,
},
ImageError(image::ImageError),
CreationError(glutin::CreationError),
ContextError(glutin::ContextError),
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidTextureSize { width, height } => write!(
f,
"failed to create a texture of the given size: {}x{}",
width, height
),
Self::ImageError(err) => write!(f, "{}", err),
Self::CreationError(err) => write!(f, "{}", err),
Self::ContextError(err) => write!(f, "{}", err),
}
}
}
impl error::Error for Error {}
#[derive(Debug)]
pub enum NewContextError {
CreationError(glutin::CreationError),
ContextError(glutin::ContextError),
}
impl Display for NewContextError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::CreationError(err) => write!(f, "{}", err),
Self::ContextError(err) => write!(f, "{}", err),
}
}
}
impl error::Error for NewContextError {}
impl From<NewContextError> for Error {
fn from(e: NewContextError) -> Self {
match e {
NewContextError::CreationError(e) => Error::CreationError(e),
NewContextError::ContextError(e) => Error::ContextError(e),
}
}
}
#[derive(Debug)]
pub enum FinalizeError {
ContextError(glutin::ContextError),
}
impl Display for FinalizeError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::ContextError(err) => write!(f, "{}", err),
}
}
}
impl error::Error for FinalizeError {}
impl From<FinalizeError> for Error {
fn from(e: FinalizeError) -> Self {
match e {
FinalizeError::ContextError(e) => Error::ContextError(e),
}
}
}
#[derive(Debug)]
pub enum LoadTextureError {
InvalidTextureSize {
width: u32,
height: u32,
},
ImageError(image::ImageError),
}
impl Display for LoadTextureError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidTextureSize { width, height } => write!(
f,
"failed to create a texture of the given size: {}x{}",
width, height
),
Self::ImageError(err) => write!(f, "{}", err),
}
}
}
impl error::Error for LoadTextureError {}
impl From<LoadTextureError> for Error {
fn from(e: LoadTextureError) -> Self {
match e {
LoadTextureError::InvalidTextureSize { width, height } => {
Error::InvalidTextureSize { width, height }
}
LoadTextureError::ImageError(e) => Error::ImageError(e),
}
}
}
#[derive(Debug)]
pub enum NewTextureError {
InvalidTextureSize {
width: u32,
height: u32,
},
}
impl Display for NewTextureError {
fn fmt<'a>(&'a self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidTextureSize { width, height } => write!(
f,
"failed to create a texture of the given size: {}x{}",
width, height
),
}
}
}
impl error::Error for NewTextureError {}
impl From<NewTextureError> for LoadTextureError {
fn from(e: NewTextureError) -> Self {
match e {
NewTextureError::InvalidTextureSize { width, height } => {
LoadTextureError::InvalidTextureSize { width, height }
}
}
}
}
impl From<NewTextureError> for Error {
fn from(e: NewTextureError) -> Self {
match e {
NewTextureError::InvalidTextureSize { width, height } => {
Error::InvalidTextureSize { width, height }
}
}
}
}