From 7765c33070d0b53cc72a8110e0b98ce67313bd5f Mon Sep 17 00:00:00 2001 From: Avril Date: Tue, 3 Aug 2021 16:19:24 +0100 Subject: [PATCH] Moved `MessageValue` to own file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for rsh's current commit: Curse − 凶 --- src/message.rs | 9 +++------ src/message/value.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 src/message/value.rs diff --git a/src/message.rs b/src/message.rs index a2b5f52..5c3f400 100644 --- a/src/message.rs +++ b/src/message.rs @@ -25,18 +25,15 @@ pub use serial::*; mod builder; pub use builder::*; +pub mod value; +pub use value::MessageValue; + /// Size of encrypted AES key pub const RSA_BLOCK_SIZE: usize = 512; /// Max size to pre-allocate when reading a message buffer. pub const MAX_ALLOC_SIZE: usize = 4096; // 4kb -/// A value that can be used for messages. -pub trait MessageValue: Serialize + for<'de> Deserialize<'de>{} - -impl MessageValue for T -where T: Serialize + for<'de> Deserialize<'de>{} - /// A message that can send a value into bytes. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Message diff --git a/src/message/value.rs b/src/message/value.rs new file mode 100644 index 0000000..536d157 --- /dev/null +++ b/src/message/value.rs @@ -0,0 +1,26 @@ +//! Message values +use super::*; + +/// A value that can be used for messages. +pub trait MessageValue: Serialize + for<'de> Deserialize<'de>{} + +impl MessageValue for T +where T: Serialize + for<'de> Deserialize<'de>{} + +/* + +use std::any::Any; +use serde::de::DeserializeOwned; + +#[derive(Debug, Serialize, Deserialize)] +pub struct DynamicMessageValue(T) +where T: Any + 'static; + + +pub struct MessageValueAnyRef<'a>(&'a (dyn Any +'static)); +pub struct MessageValueAnyMut<'a>(&'a mut (dyn Any +'static)); +pub struct MessageValueAny(Box); + +//impl MessageValue for DynamicMessageValue +//where T: Serialize + for<'de> Deserialize<'de> + Any{} + */