#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CacheableSpan {
pub base: usize,
pub end: usize,
}
impl CacheableSpan {
pub fn new(base: usize, length: usize) -> Option<Self> {
Some(Self {
base,
end: base.checked_add(length)?,
})
}
pub(crate) fn contains(&self, start: usize, end: usize) -> bool {
self.base <= start && end <= self.end
}
}
pub trait Operands {
fn source(&self) -> Option<&[u8]> {
None
}
fn allocate(&mut self, _length: usize) -> Option<&mut [u8]> {
None
}
fn cacheable_span(&self) -> Option<CacheableSpan> {
None
}
}
impl Operands for Vec<u8> {
fn source(&self) -> Option<&[u8]> {
Some(self.as_slice())
}
fn allocate(&mut self, length: usize) -> Option<&mut [u8]> {
self.resize(length, 0);
Some(self.as_mut_slice())
}
}