use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(from = "String", into = "String")]
#[non_exhaustive]
pub enum InstrumentKind {
Framework,
Delegated,
Direct,
Adjacent,
Implementing,
Other(String),
}
impl InstrumentKind {
#[must_use]
pub fn wire_str(&self) -> Option<&'static str> {
Some(match self {
Self::Framework => "framework",
Self::Delegated => "delegated",
Self::Direct => "direct",
Self::Adjacent => "adjacent",
Self::Implementing => "implementing",
Self::Other(_) => return None,
})
}
}
impl From<String> for InstrumentKind {
fn from(s: String) -> Self {
match s.as_str() {
"framework" => Self::Framework,
"delegated" => Self::Delegated,
"direct" => Self::Direct,
"adjacent" => Self::Adjacent,
"implementing" => Self::Implementing,
_ => Self::Other(s),
}
}
}
impl From<InstrumentKind> for String {
fn from(kind: InstrumentKind) -> Self {
match kind {
InstrumentKind::Other(s) => s,
modelled => modelled
.wire_str()
.expect("every non-Other variant has a wire string")
.to_owned(),
}
}
}