use std::fmt;
pub trait ReadStrategy: Default + fmt::Debug {
fn should_read(&self, start: usize, end: usize, buf_size: usize) -> bool;
}
#[derive(Debug, Default)]
pub struct IfEmpty;
impl ReadStrategy for IfEmpty {
#[inline]
fn should_read(&self, start: usize, end: usize, _: usize) -> bool {
end - start == 0
}
}
#[derive(Debug, Default)]
pub struct LessThan(pub usize);
impl ReadStrategy for LessThan {
fn should_read(&self, start: usize, end: usize, _: usize) -> bool {
end - start < self.0
}
}
pub trait MoveStrategy: Default + fmt::Debug {
fn should_move(&self, start: usize, end: usize, buf_size: usize) -> bool;
}
#[derive(Debug, Default)]
pub struct AtEndLessThan1k;
impl MoveStrategy for AtEndLessThan1k {
#[inline]
fn should_move(&self, start: usize, end: usize, buf_size: usize) -> bool {
end == buf_size && end - start < 1024
}
}
#[derive(Debug, Default)]
pub struct AtEndLessThan(pub usize);
impl MoveStrategy for AtEndLessThan {
fn should_move(&self, start: usize, end: usize, buf_size: usize) -> bool {
end == buf_size && end - start < self.0
}
}
#[derive(Debug, Default)]
pub struct NeverMove;
impl MoveStrategy for NeverMove {
#[inline]
fn should_move(&self, _: usize, _: usize, _: usize) -> bool {
false
}
}