Moved `MessageValue` to own file

Fortune for rsh's current commit: Curse − 凶
message-write-to-buf
Avril 3 years ago
parent ab97278dbd
commit 7765c33070
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -25,18 +25,15 @@ pub use serial::*;
mod builder; mod builder;
pub use builder::*; pub use builder::*;
pub mod value;
pub use value::MessageValue;
/// Size of encrypted AES key /// Size of encrypted AES key
pub const RSA_BLOCK_SIZE: usize = 512; pub const RSA_BLOCK_SIZE: usize = 512;
/// Max size to pre-allocate when reading a message buffer. /// Max size to pre-allocate when reading a message buffer.
pub const MAX_ALLOC_SIZE: usize = 4096; // 4kb 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<T: ?Sized> MessageValue for T
where T: Serialize + for<'de> Deserialize<'de>{}
/// A message that can send a value into bytes. /// A message that can send a value into bytes.
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Message<V: ?Sized + MessageValue> pub struct Message<V: ?Sized + MessageValue>

@ -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<T: ?Sized> 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>(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<dyn Any +'static>);
//impl<T> MessageValue for DynamicMessageValue<T>
//where T: Serialize + for<'de> Deserialize<'de> + Any{}
*/
Loading…
Cancel
Save