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}
16
17#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
22pub struct Notice {
23 pub kind: NoticeKind,
24 pub source: String,
26 pub text: String,
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32 use serde_json::json;
33
34 #[test]
36 fn notice_kind_serde_snake_case_round_trip() {
37 for (kind, tag) in [
38 (NoticeKind::Warning, "warning"),
39 (NoticeKind::Progress, "progress"),
40 (NoticeKind::Info, "info"),
41 ] {
42 let v = serde_json::to_value(&kind).unwrap();
43 assert_eq!(v, json!(tag));
44 let back: NoticeKind = serde_json::from_value(v).unwrap();
45 assert_eq!(&back, &kind);
46 }
47 }
48
49 #[test]
50 fn notice_serde_round_trip() {
51 let notice = Notice {
52 kind: NoticeKind::Warning,
53 source: "guard".to_string(),
54 text: "judge unparsed โ treating as complete".to_string(),
55 };
56 let v = serde_json::to_value(¬ice).unwrap();
57 assert_eq!(v["kind"], json!("warning"));
58 assert_eq!(v["source"], json!("guard"));
59 assert_eq!(v["text"], json!("judge unparsed โ treating as complete"));
60
61 let back: Notice = serde_json::from_value(v).unwrap();
62 assert_eq!(back, notice);
63 }
64}