1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7#[serde(rename_all = "snake_case")]
8pub enum NoticeKind {
9 Warning,
11 Progress,
13 Info,
15 Attention,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
28pub struct Notice {
29 pub kind: NoticeKind,
30 pub source: String,
32 pub text: String,
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38 use serde_json::json;
39
40 #[test]
42 fn notice_kind_serde_snake_case_round_trip() {
43 for (kind, tag) in [
44 (NoticeKind::Warning, "warning"),
45 (NoticeKind::Progress, "progress"),
46 (NoticeKind::Info, "info"),
47 (NoticeKind::Attention, "attention"),
48 ] {
49 let v = serde_json::to_value(&kind).unwrap();
50 assert_eq!(v, json!(tag));
51 let back: NoticeKind = serde_json::from_value(v).unwrap();
52 assert_eq!(&back, &kind);
53 }
54 }
55
56 #[test]
57 fn notice_serde_round_trip() {
58 let notice = Notice {
59 kind: NoticeKind::Warning,
60 source: "guard".to_string(),
61 text: "judge unparsed โ treating as complete".to_string(),
62 };
63 let v = serde_json::to_value(¬ice).unwrap();
64 assert_eq!(v["kind"], json!("warning"));
65 assert_eq!(v["source"], json!("guard"));
66 assert_eq!(v["text"], json!("judge unparsed โ treating as complete"));
67
68 let back: Notice = serde_json::from_value(v).unwrap();
69 assert_eq!(back, notice);
70 }
71}