rubbo_core/protocol/
kind.rs1use serde::{Serialize, Deserialize};
2use std::str::FromStr;
3use crate::error::{Error, Result};
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
6#[derive(Default)]
7pub enum ProtocolKind {
8 #[default]
9 Triple,
10 Dubbo,
11 Unknown(String),
12}
13
14
15impl FromStr for ProtocolKind {
16 type Err = Error;
17
18 fn from_str(s: &str) -> Result<Self> {
19 match s.to_lowercase().as_str() {
20 "triple" | "tri" => Ok(ProtocolKind::Triple),
21 "dubbo" => Ok(ProtocolKind::Dubbo),
22 _ => Ok(ProtocolKind::Unknown(s.to_string())),
23 }
24 }
25}
26
27impl std::fmt::Display for ProtocolKind {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 match self {
30 ProtocolKind::Triple => write!(f, "tri"),
31 ProtocolKind::Dubbo => write!(f, "dubbo"),
32 ProtocolKind::Unknown(s) => write!(f, "{}", s),
33 }
34 }
35}