use serde::{Deserialize, Serialize};
#[cfg(doc)]
use super::ProcessInfo;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
#[non_exhaustive]
pub enum ActionOutcome {
Replied {
body: String,
},
NoChannel,
Skipped,
TimedOut,
DogNoChannel,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ActionReply {
pub id: u32,
pub name: String,
pub outcome: ActionOutcome,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
#[non_exhaustive]
pub enum SignalOutcome {
Delivered,
NotRunning,
Failed {
reason: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SignalReply {
pub id: u32,
pub name: String,
pub outcome: SignalOutcome,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
#[non_exhaustive]
pub enum LineOutcome {
Sent,
NoStdin,
NotWritten {
reason: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct LineReply {
pub id: u32,
pub name: String,
pub outcome: LineOutcome,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn action_outcome_kinds_serialize_snake_case_and_round_trip() {
let cases = [
(
ActionOutcome::Replied {
body: "pong".to_string(),
},
r#"{"kind":"replied","body":"pong"}"#,
),
(ActionOutcome::NoChannel, r#"{"kind":"no_channel"}"#),
(ActionOutcome::Skipped, r#"{"kind":"skipped"}"#),
(ActionOutcome::TimedOut, r#"{"kind":"timed_out"}"#),
(ActionOutcome::DogNoChannel, r#"{"kind":"dog_no_channel"}"#),
];
for (outcome, wire) in cases {
assert_eq!(
serde_json::to_string(&outcome).unwrap(),
wire,
"{outcome:?}"
);
assert_eq!(
serde_json::from_str::<ActionOutcome>(wire).unwrap(),
outcome
);
}
}
}