123456789101112131415161718192021 |
- //! Common features shared between requests and responses
- //!
- use serde_json::Value;
- use std::collections::VecDeque;
- /// Serialize and Deserialize a message type
- ///
- /// All messages inner types must implement this trait
- pub trait SerializeDeserialize {
- /// The tag to identity the message by
- fn get_tag() -> &'static str;
- /// How to serialize into JSON. It must return a vector of serde_json::Value
- fn serialize(&self) -> Result<Vec<Value>, String>;
- /// How to deserialize, the first element (the tag) is already removed
- /// before passing to this method
- fn deserialize(array: VecDeque<Value>) -> Result<Self, String>
- where
- Self: Sized;
- }
|