#[derive(Debug, Clone, Copy)]
pub(crate) enum DownstreamStateMachine {
Reading,
ReadingFinished,
Errored,
}
#[allow(clippy::wrong_self_convention)]
impl DownstreamStateMachine {
pub fn new(finished: bool) -> Self {
if finished {
Self::ReadingFinished
} else {
Self::Reading
}
}
pub fn can_poll(&self) -> bool {
!matches!(self, Self::Errored)
}
pub fn is_reading(&self) -> bool {
matches!(self, Self::Reading)
}
pub fn is_done(&self) -> bool {
!matches!(self, Self::Reading)
}
pub fn is_errored(&self) -> bool {
matches!(self, Self::Errored)
}
pub fn maybe_finished(&mut self, set: bool) {
if set {
*self = Self::ReadingFinished
}
}
pub fn to_errored(&mut self) {
*self = Self::Errored
}
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct ResponseStateMachine {
upstream_response_done: bool,
cached_response_done: bool,
}
impl ResponseStateMachine {
pub fn new() -> Self {
ResponseStateMachine {
upstream_response_done: false,
cached_response_done: true, }
}
pub fn is_done(&self) -> bool {
self.upstream_response_done && self.cached_response_done
}
pub fn upstream_done(&self) -> bool {
self.upstream_response_done
}
pub fn cached_done(&self) -> bool {
self.cached_response_done
}
pub fn enable_cached_response(&mut self) {
self.cached_response_done = false;
}
pub fn maybe_set_upstream_done(&mut self, done: bool) {
if done {
self.upstream_response_done = true;
}
}
pub fn maybe_set_cache_done(&mut self, done: bool) {
if done {
self.cached_response_done = true;
}
}
}