use core::ops::Deref;
use std::sync::Arc;
use std::vec::Vec;
pub trait BufSource {
type Output: AsRef<[u8]> + AsMut<[u8]>;
fn create_buf(&self) -> Self::Output;
fn create_sized(&self, size: usize) -> Self::Output;
}
impl<T: BufSource> BufSource for Arc<T> {
type Output = T::Output;
fn create_buf(&self) -> Self::Output {
Arc::deref(self).create_buf()
}
fn create_sized(&self, size: usize) -> Self::Output {
Arc::deref(self).create_sized(size)
}
}
#[derive(Clone)]
pub struct VecBufSource;
impl BufSource for VecBufSource {
type Output = Vec<u8>;
fn create_buf(&self) -> Self::Output {
vec![0; 1024]
}
fn create_sized(&self, size: usize) -> Self::Output {
vec![0; size]
}
}