aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api/message.rs
blob: 365a427a407ac6b5a1973d12729fb0f4150d14b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
pub use super::generated_api::api::message::Message as ProtobufMessage;
use crate::data::PluginMessage;

use std::convert::TryFrom;

impl TryFrom<ProtobufMessage> for PluginMessage {
    type Error = &'static str;
    fn try_from(protobuf_message: ProtobufMessage) -> Result<Self, &'static str> {
        let name = protobuf_message.name;
        let payload = protobuf_message.payload;
        let worker_name = protobuf_message.worker_name;
        Ok(PluginMessage {
            name,
            payload,
            worker_name,
        })
    }
}

impl TryFrom<PluginMessage> for ProtobufMessage {
    type Error = &'static str;
    fn try_from(plugin_message: PluginMessage) -> Result<Self, &'static str> {
        Ok(ProtobufMessage {
            name: plugin_message.name,
            payload: plugin_message.payload,
            worker_name: plugin_message.worker_name,
        })
    }
}