diskann_disk/build/chunking/continuation/
continuation_tracker.rs1use std::time::Duration;
7
8pub enum ContinuationGrant {
10 Continue,
11 Yield(Duration),
12 Stop,
13}
14
15pub trait ContinuationTrackerTrait: Send + Sync + ContinuationCheckerTraitClone {
18 fn get_continuation_grant(&self) -> ContinuationGrant;
19}
20
21#[derive(Default, Clone)]
24pub struct NaiveContinuationTracker {}
25
26impl ContinuationTrackerTrait for NaiveContinuationTracker {
27 fn get_continuation_grant(&self) -> ContinuationGrant {
28 ContinuationGrant::Continue
29 }
30}
31
32pub trait ContinuationCheckerTraitClone {
33 fn clone_box(&self) -> Box<dyn ContinuationTrackerTrait>;
34}
35
36impl<T> ContinuationCheckerTraitClone for T
37where
38 T: 'static + ContinuationTrackerTrait + Clone,
39{
40 fn clone_box(&self) -> Box<dyn ContinuationTrackerTrait> {
41 Box::new(self.clone())
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_naive_continuation_tracker_default() {
51 let tracker = NaiveContinuationTracker::default();
52 match tracker.get_continuation_grant() {
54 ContinuationGrant::Continue => {}
55 _ => panic!("Expected Continue"),
56 }
57 }
58
59 #[test]
60 fn test_naive_continuation_tracker_clone_box() {
61 let tracker = NaiveContinuationTracker::default();
62 let boxed = tracker.clone_box();
63
64 match boxed.get_continuation_grant() {
66 ContinuationGrant::Continue => {}
67 _ => panic!("Expected Continue"),
68 }
69 }
70}