text_document_common/
snapshot.rs1use serde::{Deserialize, Serialize};
4use std::any::Any;
5
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
8pub struct EntityTreeSnapshot {
9 #[serde(skip)]
11 pub store_snapshot: Option<StoreSnapshot>,
12}
13
14pub 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#[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}