use std::any::Any;
use crate::error::ContextError;
pub trait ContextValue: Any + Send + Sync {
fn as_any(&self) -> &dyn Any;
fn serialize_value(&self) -> Result<Vec<u8>, ContextError>;
fn is_local(&self) -> bool;
}
impl<T> ContextValue for T
where
T: Clone + Send + Sync + serde::Serialize + serde::de::DeserializeOwned + 'static,
{
fn as_any(&self) -> &dyn Any {
self
}
fn serialize_value(&self) -> Result<Vec<u8>, ContextError> {
bincode::serialize(self).map_err(|e| ContextError::SerializationFailed(e.to_string()))
}
fn is_local(&self) -> bool {
false
}
}