zero4rs 2.0.0

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

use bytestring::ByteString;

#[derive(Serialize, Deserialize)]
pub enum Action {
    // {"id": "1", "action": "Subscribe", "data": {"channel": "ServerTime"}}
    // {"id": "2", "action": "Unsubscribe", "data": {"channel": "ServerTime"}}
    Subscribe,
    Unsubscribe,

    // {"id": "3", "action": "SendMessage", "data": {"to": "ServerTime", "msg": "add"}}
    SendMessage, // 发送聊天信息
}

#[derive(Serialize, Deserialize, ActixMessage)]
#[rtype(result = "()")]
pub struct Input {
    pub id: Option<String>,
    pub action: Action,
    pub data: Value,
}

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
    }
}