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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
mod id;
mod kind;
pub use self::{
id::{StickerId, StickerPackId},
kind::{StickerFormatType, StickerFormatTypeConversionError},
};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Sticker {
pub asset: String,
pub description: String,
pub format_type: StickerFormatType,
pub id: StickerId,
pub name: String,
pub pack_id: StickerPackId,
pub preview_asset: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<String>,
}
#[cfg(test)]
mod tests {
use super::{Sticker, StickerFormatType, StickerId, StickerPackId};
use serde_test::Token;
#[test]
fn test_minimal() {
let value = Sticker {
asset: "foo1".to_owned(),
description: "foo2".to_owned(),
format_type: StickerFormatType::Png,
id: StickerId(1),
name: "sticker name".to_owned(),
pack_id: StickerPackId(2),
preview_asset: None,
tags: Some("foo,bar,baz".to_owned()),
};
serde_test::assert_tokens(
&value,
&[
Token::Struct {
name: "Sticker",
len: 8,
},
Token::Str("asset"),
Token::Str("foo1"),
Token::Str("description"),
Token::Str("foo2"),
Token::Str("format_type"),
Token::U8(1),
Token::Str("id"),
Token::NewtypeStruct { name: "StickerId" },
Token::Str("1"),
Token::Str("name"),
Token::Str("sticker name"),
Token::Str("pack_id"),
Token::NewtypeStruct {
name: "StickerPackId",
},
Token::Str("2"),
Token::Str("preview_asset"),
Token::None,
Token::Str("tags"),
Token::Some,
Token::Str("foo,bar,baz"),
Token::StructEnd,
],
);
}
}