pub trait AsEnum {
    fn as_enum(&self) -> gl::GLenum;
}

pub trait Bindable {
    fn bind(&self);
    fn unbind(&self);
}

pub struct BindGuard<T>
where
    T: Bindable,
{
    bindable: T,
}

impl<T> BindGuard<T>
where
    T: Bindable,
{
    pub fn new(bindable: T) -> Self {
        bindable.bind();

        Self { bindable }
    }
}

impl<T> Drop for BindGuard<T>
where
    T: Bindable,
{
    fn drop(&mut self) {
        self.bindable.unbind()
    }
}

impl<T> Bindable for &T
where
    T: Bindable,
{
    fn bind(&self) {
        (*self).bind();
    }

    fn unbind(&self) {
        (*self).bind();
    }
}
