parent
ab97278dbd
commit
af19935167
@ -0,0 +1,32 @@
|
|||||||
|
//! Message values
|
||||||
|
use super::*;
|
||||||
|
use std::any::Any;
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
|
pub struct MessageValueAnyRef<'a>(&'a (dyn Any +'static));
|
||||||
|
pub struct MessageValueAnyMut<'a>(&'a mut (dyn Any +'static));
|
||||||
|
pub struct MessageValueAny(Box<dyn Any +'static>);
|
||||||
|
|
||||||
|
/// A value that can be used for messages.
|
||||||
|
pub trait MessageValue: Serialize + for<'de> Deserialize<'de>
|
||||||
|
{
|
||||||
|
fn as_dynamic(&self) -> Option<MessageValueAnyRef<'_>> { None }
|
||||||
|
fn as_dynamic_mut(&mut self) -> Option<MessageValueAnyMut<'_>> { None }
|
||||||
|
fn into_dynamic(self) -> Result<MessageValueAny, Self> { Err(self) }
|
||||||
|
}
|
||||||
|
|
||||||
|
default impl<T: ?Sized> MessageValue for T
|
||||||
|
where T: Serialize + for<'de> Deserialize<'de>
|
||||||
|
{
|
||||||
|
default fn as_dynamic(&self) -> Option<MessageValueAnyRef<'_>> { None }
|
||||||
|
default fn as_dynamic_mut(&mut self) -> Option<MessageValueAnyMut<'_>> { None }
|
||||||
|
default fn into_dynamic(self) -> Result<MessageValueAny, Self> { Err(self) }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct DynamicMessageValue<T>(T)
|
||||||
|
where T: Any + 'static;
|
||||||
|
|
||||||
|
//impl<T> MessageValue for DynamicMessageValue<T>
|
||||||
|
//where T: Serialize + for<'de> Deserialize<'de> + Any{}
|
||||||
|
|
Loading…
Reference in new issue