azure_functions/send_grid/
attachment.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Default, Clone, Serialize, Deserialize)]
5pub struct Attachment {
6 pub content: String,
8 #[serde(rename = "type")]
10 pub mime_type: String,
11 pub filename: String,
13 #[serde(skip_serializing_if = "Option::is_none")]
20 pub disposition: Option<String>,
21 #[serde(skip_serializing_if = "Option::is_none")]
29 pub content_id: Option<String>,
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35 use serde_json::to_string;
36
37 #[test]
38 fn it_serializes_to_json() {
39 let json = to_string(&Attachment {
40 content: "aGVsbG8gd29ybGQ=".to_owned(),
41 mime_type: "text/plain".to_owned(),
42 filename: "foo.txt".to_owned(),
43 disposition: None,
44 content_id: None,
45 })
46 .unwrap();
47
48 assert_eq!(
49 json,
50 r#"{"content":"aGVsbG8gd29ybGQ=","type":"text/plain","filename":"foo.txt"}"#
51 );
52
53 let json = to_string(&Attachment {
54 content: "aGVsbG8gd29ybGQ=".to_owned(),
55 mime_type: "text/plain".to_owned(),
56 filename: "foo.txt".to_owned(),
57 disposition: Some("inline".to_owned()),
58 content_id: Some("123456".to_owned()),
59 })
60 .unwrap();
61
62 assert_eq!(
63 json,
64 r#"{"content":"aGVsbG8gd29ybGQ=","type":"text/plain","filename":"foo.txt","disposition":"inline","content_id":"123456"}"#
65 );
66 }
67}