use glutin;
use std::{convert, ffi, string};

#[derive(Debug)]
pub enum Error {
    BadCString,
    InvalidShaderLog,
    CompileError(String),
    LinkError(String),
    GlutinCreation(glutin::CreationError),
    GlutinContext(glutin::ContextError),
}

impl convert::From<glutin::CreationError> for Error {
    fn from(err: glutin::CreationError) -> Error {
        Error::GlutinCreation(err)
    }
}

impl convert::From<glutin::ContextError> for Error {
    fn from(err: glutin::ContextError) -> Error {
        Error::GlutinContext(err)
    }
}

impl convert::From<ffi::NulError> for Error {
    fn from(_: ffi::NulError) -> Error {
        Error::BadCString
    }
}

impl convert::From<string::FromUtf8Error> for Error {
    fn from(_: string::FromUtf8Error) -> Error {
        Error::InvalidShaderLog
    }
}
