use serde::{Deserialize, Serialize};
use std::any::Any;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct EntityTreeSnapshot {
#[serde(skip)]
pub store_snapshot: Option<StoreSnapshot>,
}
pub trait StoreSnapshotTrait: std::fmt::Debug + Send + Sync {
fn clone_box(&self) -> Box<dyn StoreSnapshotTrait>;
fn as_any(&self) -> &dyn Any;
}
impl Clone for Box<dyn StoreSnapshotTrait> {
fn clone(&self) -> Self {
self.clone_box()
}
}
#[derive(Debug, Clone)]
pub struct StoreSnapshot {
inner: Box<dyn StoreSnapshotTrait>,
}
impl StoreSnapshot {
pub fn new<T: StoreSnapshotTrait + 'static>(inner: T) -> Self {
Self {
inner: Box::new(inner),
}
}
pub fn downcast_ref<T: 'static>(&self) -> Option<&T> {
self.inner.as_any().downcast_ref()
}
}