use std::fmt;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CeremonyInterventionIntent {
Question,
Feedback,
Constraint,
Checkpoint,
}
impl CeremonyInterventionIntent {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Question => "question",
Self::Feedback => "feedback",
Self::Constraint => "constraint",
Self::Checkpoint => "checkpoint",
}
}
#[must_use]
pub const fn expects_response(self) -> bool {
matches!(self, Self::Question | Self::Checkpoint)
}
}
impl fmt::Display for CeremonyInterventionIntent {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn only_the_intents_that_ask_expect_an_answer() {
assert!(CeremonyInterventionIntent::Question.expects_response());
assert!(CeremonyInterventionIntent::Checkpoint.expects_response());
assert!(!CeremonyInterventionIntent::Feedback.expects_response());
assert!(!CeremonyInterventionIntent::Constraint.expects_response());
}
#[test]
fn wire_names_are_the_labels() {
assert_eq!(
serde_json::to_value(CeremonyInterventionIntent::Constraint).unwrap(),
serde_json::json!("constraint")
);
assert_eq!(CeremonyInterventionIntent::Feedback.to_string(), "feedback");
}
}