openrtb_native1/
context_sub_type.rs

1/// 7.2 Context Sub Type IDs
2///
3/// Next-level context in which the ad appears. Again this reflects the primary context, and does
4/// not imply no presence of other elements. For example, an article is likely to contain images but
5/// is still first and foremost an article. SubType should only be combined with the primary context
6/// type as indicated (ie for a context type of 1, only context subtypes that start with 1 are
7/// valid).
8#[derive(Debug, PartialEq, Eq, Clone, Copy)]
9pub enum ContextSubType {
10    /// General or mixed content
11    GeneralOrMixed,
12    /// Primarily article content (which of course could include images, etc 11 as part of the
13    /// article)
14    Article,
15    /// Primarily video content
16    Video,
17    /// Primarily audio content
18    Audio,
19    /// Primarily image content
20    Image,
21    /// User-generated content - forums, comments, etc
22    UserGenerated,
23    /// General social content such as a general social network
24    Social,
25    /// Primarily email content
26    Email,
27    /// Primarily chat/IM content
28    Chat,
29    /// Content focused on selling products, whether digital or physical
30    Selling,
31    /// Application store/marketplace
32    Marketplace,
33    /// Product reviews site primarily (which may sell product secondarily)
34    Review,
35    /// To be defined by the exchange
36    ExchangeSpecific(i32),
37}
38
39crate::impl_enum_serde!(
40    #[exchange(ident = ExchangeSpecific, greater = 500)]
41    ContextSubType {
42        GeneralOrMixed = 10,
43        Article = 11,
44        Video = 12,
45        Audio = 13,
46        Image = 14,
47        UserGenerated = 15,
48        Social = 20,
49        Email = 21,
50        Chat = 22,
51        Selling = 30,
52        Marketplace = 31,
53        Review = 32,
54    }
55);
56
57#[cfg(test)]
58mod test {
59    use super::*;
60
61    #[test]
62    fn json() -> serde_json::Result<()> {
63        assert!(serde_json::from_str::<ContextSubType>("0").is_err());
64        assert!(serde_json::from_str::<ContextSubType>("500").is_err());
65
66        let json = "[10,20,30,501]";
67        let e1: Vec<ContextSubType> = serde_json::from_str(json)?;
68        assert_eq!(serde_json::to_string(&e1)?, json);
69        assert_eq!(
70            e1,
71            vec![
72                ContextSubType::GeneralOrMixed,
73                ContextSubType::Social,
74                ContextSubType::Selling,
75                ContextSubType::ExchangeSpecific(501),
76            ]
77        );
78
79        Ok(())
80    }
81}