Skip to main content

text_document_common/
snapshot.rs

1// Generated by Qleany v1.4.8 from snapshot.tera
2
3use serde::{Deserialize, Serialize};
4use std::any::Any;
5
6/// Snapshot of an entity tree, backed by a store-level snapshot for undo.
7#[derive(Debug, Clone, Default, Serialize, Deserialize)]
8pub struct EntityTreeSnapshot {
9    /// Store-level fast path for undo.
10    #[serde(skip)]
11    pub store_snapshot: Option<StoreSnapshot>,
12}
13
14// ─────────────────────────────────────────────────────────────────────────────
15// Store-level snapshot (type-erased so snapshot.rs doesn't depend on HashMapStore)
16// ─────────────────────────────────────────────────────────────────────────────
17
18/// Trait for type-erased store snapshots.
19pub trait StoreSnapshotTrait: std::fmt::Debug + Send + Sync {
20    fn clone_box(&self) -> Box<dyn StoreSnapshotTrait>;
21    fn as_any(&self) -> &dyn Any;
22}
23
24impl Clone for Box<dyn StoreSnapshotTrait> {
25    fn clone(&self) -> Self {
26        self.clone_box()
27    }
28}
29
30/// Type-erased store snapshot for undo fast path.
31#[derive(Debug, Clone)]
32pub struct StoreSnapshot {
33    inner: Box<dyn StoreSnapshotTrait>,
34}
35
36impl StoreSnapshot {
37    pub fn new<T: StoreSnapshotTrait + 'static>(inner: T) -> Self {
38        Self {
39            inner: Box::new(inner),
40        }
41    }
42
43    pub fn downcast_ref<T: 'static>(&self) -> Option<&T> {
44        self.inner.as_any().downcast_ref()
45    }
46}