pel 0.1.0

OpenGL backed framebuffer
Documentation
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,
        }
    }
}