1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use serde::Serialize;

/// Communication channel the message is sent on
#[derive(Serialize, Debug, PartialEq)]
pub enum Channel {
  #[serde(rename = "sms")]
  SMS,
  #[serde(rename = "whatsapp")]
  WhatsApp,
  Unknown,
}

impl std::fmt::Display for Channel {
  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
    write!(f, "{:?}", self)
  }
}

#[test]
fn test_channel_serialize() {
  assert_eq!(
    String::from("\"sms\""),
    serde_json::to_string(&Channel::SMS).unwrap()
  );

  assert_eq!(
    String::from("\"whatsapp\""),
    serde_json::to_string(&Channel::WhatsApp).unwrap()
  );
}