use super::{
super::context::{Error, GLError},
Binder,
};
pub trait Allocate<Src> {
type Error;
fn allocate(&mut self, src: Src, usage: u32) -> Result<&mut Self, Self::Error>;
}
impl<'a, 'target, 'buffer, const TARGET: u32> Allocate<&'a [u8]>
for Binder<'target, 'buffer, TARGET>
{
type Error = Error;
fn allocate(&mut self, src: &'a [u8], usage: u32) -> Result<&mut Self, Error> {
self.target.buffer_data_with_u8_array(TARGET, src, usage);
self.target.error()?;
Ok(self)
}
}
impl<'target, 'buffer, const TARGET: u32> Allocate<i32> for Binder<'target, 'buffer, TARGET> {
type Error = Error;
fn allocate(&mut self, src: i32, usage: u32) -> Result<&mut Self, Error> {
self.target.buffer_data_with_i32(TARGET, src, usage);
self.target.error()?;
Ok(self)
}
}
impl<'a, 'target, 'target2, 'buffer, 'buffer2, const TARGET: u32, const TARGET2: u32>
Allocate<&'a mut Binder<'target2, 'buffer2, TARGET2>> for Binder<'target, 'buffer, TARGET>
{
type Error = Box<dyn std::error::Error>;
fn allocate(
&mut self,
src: &'a mut Binder<'target2, 'buffer2, TARGET2>,
usage: u32,
) -> Result<&mut Self, Box<dyn std::error::Error>> {
self.allocate(src.len() as i32, usage)?;
use super::io::Read;
let mut dst = self.sub(..);
src.sub(..).read(&mut dst)?;
Ok(self)
}
}