common.rs 683 B

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