extern crate alloc;
use super::*;
pub struct BoxBuffer {
code: u8,
data: alloc::boxed::Box<[u8]>,
}
impl BoxBuffer {
pub fn new(length: usize) -> Self {
Self {
code: 0,
data: alloc::vec![0; length].into_boxed_slice(),
}
}
}
impl MessageBuffer for BoxBuffer {
fn code(&self) -> u8 {
self.code
}
fn tail(&self) -> &[u8] {
&self.data
}
#[cfg(feature = "downcast")]
fn static_variant() -> Option<LifetimesMatterLittle<impl 'static + MessageBuffer>> {
Some(unsafe { LifetimesMatterLittle::<Self>::new() })
}
}
impl MessageBufferMut for BoxBuffer {
fn code_mut(&mut self) -> &mut u8 {
&mut self.code
}
fn tail_mut(&mut self) -> &mut [u8] {
&mut self.data
}
#[cfg(feature = "downcast")]
fn static_mut_variant() -> Option<LifetimesMatterLittle<impl 'static + MessageBufferMut>> {
Some(unsafe { LifetimesMatterLittle::<Self>::new() })
}
}