summaryrefslogtreecommitdiff
path: root/rust/crates/commands/src/preview_tracker.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/crates/commands/src/preview_tracker.rs')
-rw-r--r--rust/crates/commands/src/preview_tracker.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/rust/crates/commands/src/preview_tracker.rs b/rust/crates/commands/src/preview_tracker.rs
new file mode 100644
index 00000000..4eb7484d
--- /dev/null
+++ b/rust/crates/commands/src/preview_tracker.rs
@@ -0,0 +1,28 @@
+#[derive(Clone, Debug, Default)]
+pub struct PreviewTracker<T> {
+ snapshot: Option<T>,
+}
+
+impl<T: Clone> PreviewTracker<T> {
+ pub fn new() -> Self {
+ Self { snapshot: None }
+ }
+
+ pub fn begin(&mut self, state: &T) {
+ if self.snapshot.is_none() {
+ self.snapshot = Some(state.clone());
+ }
+ }
+
+ pub fn is_active(&self) -> bool {
+ self.snapshot.is_some()
+ }
+
+ pub fn snapshot(&self) -> Option<&T> {
+ self.snapshot.as_ref()
+ }
+
+ pub fn end(&mut self) -> Option<T> {
+ self.snapshot.take()
+ }
+}