zero4rs 2.0.0

zero4rs is a powerful, pragmatic, and extremely fast web framework for Rust
Documentation
use actix::Message as ActixMessage;

use std::str::FromStr;

use crate::websocket::webchat::input::subscribes::SubscribeChannel;
use crate::websocket::webchat::ConnectId;

#[derive(ActixMessage)]
#[rtype(result = "()")]
pub struct UnsubscribeAction {
    pub id: ConnectId,
    pub channel: SubscribeChannel,
}

impl UnsubscribeAction {
    pub fn parse(
        connection_id: &str,
        data: &serde_json::Value,
    ) -> Result<UnsubscribeAction, String> {
        match crate::commons::get_value_as_string(data, "channel") {
            Ok(Some(c)) => match SubscribeChannel::from_str(&c) {
                Ok(channel) => Ok(UnsubscribeAction {
                    id: connection_id.to_owned(),
                    channel,
                }),
                Err(_) => Err(format!("invalid channel: {}", c)),
            },
            Ok(None) => Err("channel is required".to_string()),
            Err(err) => Err(format!("invalid channel: error={}", err)),
        }
    }
}