zero4rs 2.0.0

zero4rs is a powerful, pragmatic, and extremely fast web framework for Rust
Documentation
use serde::{Deserialize, Serialize};
use serde_json::Value;

use bytestring::ByteString;

// {"id": "1", "action": "Subscribe", "data": {"channel": "ServerTime"}}
// {"id": "2", "action": "Unsubscribe", "data": {"channel": "ServerTime"}}
// {"id": "3", "action": "Talk", "data": {"to": "user_id_here", "to_role": "normal_user", "msg": "hello, jim", "msg_type": "text"}}
// {"id": "4", "action": "History", "data": {"to": "user_id_here"}}
// {"id": "5", "action": "HistoryTalk"}
// {"id": "4", "action": "Autorization", "data": {"token": "user_id_here"}}
#[derive(Serialize, Deserialize, Debug)]
pub struct Input {
    pub id: Option<String>,
    pub action: Action,
    pub data: Option<Value>,
}

#[rustfmt::skip]
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq, strum_macros::EnumString)]
// #[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, strum_macros::EnumString)]
pub enum Action {
    Subscribe,
    Unsubscribe,

    Autorization,

    Talk, // 对话消息, 对方可能是一个人或群组, 或频道
    History, // 查询历史消息
    HistoryTalk, // 查询历史对话
    PostLocation, // 上报位置
}

impl From<Input> for ByteString {
    fn from(val: Input) -> Self {
        let json_string = serde_json::to_string(&val).unwrap();
        let byte_string: ByteString = ByteString::from(json_string);

        byte_string
    }
}