dex_sdk/
time_travel_options.rs1use std::time::SystemTime;
10
11use crate::{Step, StepExecutionId};
12
13#[derive(Clone, Debug)]
14pub struct TimeTravelOptions {
19 pub(crate) point: TimeTravelPoint,
20 pub(crate) reason: Option<String>,
21 pub(crate) skip_writes_reapply: bool,
22}
23
24#[derive(Clone, Debug)]
25pub(crate) enum TimeTravelPoint {
26 Beginning,
27 HistoryEventTime(SystemTime),
28 StepType(&'static str),
29 StepExecution(StepExecutionId, TimeTravelStepMethod),
30}
31
32#[derive(Clone, Copy, Debug)]
33pub enum TimeTravelStepMethod {
35 WaitFor,
37 Execute,
39}
40
41impl TimeTravelOptions {
42 pub fn from_beginning() -> Self {
44 Self::new(TimeTravelPoint::Beginning)
45 }
46
47 pub fn from_history_event_time(event_time: SystemTime) -> Self {
49 Self::new(TimeTravelPoint::HistoryEventTime(event_time))
50 }
51
52 pub fn from_step<SomeStep: Step>(step: &SomeStep) -> Self {
54 Self::new(TimeTravelPoint::StepType(step.step_type()))
55 }
56
57 pub fn from_step_execution(
59 step_execution: StepExecutionId,
60 method: TimeTravelStepMethod,
61 ) -> Self {
62 Self::new(TimeTravelPoint::StepExecution(step_execution, method))
63 }
64
65 pub fn reason(mut self, reason: impl Into<String>) -> Self {
67 self.reason = Some(reason.into());
68 self
69 }
70
71 pub fn skip_writes_reapply(mut self, skip: bool) -> Self {
73 self.skip_writes_reapply = skip;
74 self
75 }
76
77 fn new(point: TimeTravelPoint) -> Self {
78 Self {
79 point,
80 reason: None,
81 skip_writes_reapply: false,
82 }
83 }
84}