use std::time::Duration;
pub enum ContinuationGrant {
Continue,
Yield(Duration),
Stop,
}
pub trait ContinuationTrackerTrait: Send + Sync + ContinuationCheckerTraitClone {
fn get_continuation_grant(&self) -> ContinuationGrant;
}
#[derive(Default, Clone)]
pub struct NaiveContinuationTracker {}
impl ContinuationTrackerTrait for NaiveContinuationTracker {
fn get_continuation_grant(&self) -> ContinuationGrant {
ContinuationGrant::Continue
}
}
pub trait ContinuationCheckerTraitClone {
fn clone_box(&self) -> Box<dyn ContinuationTrackerTrait>;
}
impl<T> ContinuationCheckerTraitClone for T
where
T: 'static + ContinuationTrackerTrait + Clone,
{
fn clone_box(&self) -> Box<dyn ContinuationTrackerTrait> {
Box::new(self.clone())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_naive_continuation_tracker_default() {
let tracker = NaiveContinuationTracker::default();
match tracker.get_continuation_grant() {
ContinuationGrant::Continue => {}
_ => panic!("Expected Continue"),
}
}
#[test]
fn test_naive_continuation_tracker_clone_box() {
let tracker = NaiveContinuationTracker::default();
let boxed = tracker.clone_box();
match boxed.get_continuation_grant() {
ContinuationGrant::Continue => {}
_ => panic!("Expected Continue"),
}
}
}