openrtb_native1/
context_type.rs

1/// 7.1 Context Type IDs
2///
3/// The context in which the ad appears - what type of content is surrounding the ad on the page at
4/// a high level. This maps directly to the new Deep Dive on In-Feed Ad Units. This denotes the
5/// primary context, but does not imply other content may not exist on the page - for example it's
6/// expected that most content platforms have some social components, etc.
7#[derive(Debug, PartialEq, Eq, Clone, Copy)]
8pub enum ContextType {
9    /// Content-centric context such as newsfeed, article, image gallery, video gallery, or
10    /// similar.
11    Content,
12    /// Social-centric context such as social network feed, email, chat, or similar.
13    Social,
14    /// Product context such as product listings, details, recommendations, reviews, or similar.
15    Product,
16    /// To be defined by the exchange.
17    ExchangeSpecific(i32),
18}
19
20crate::impl_enum_serde!(
21    #[exchange(ident = ExchangeSpecific, greater = 500)]
22    ContextType {
23        Content = 1,
24        Social = 2,
25        Product = 3,
26    }
27);
28
29#[cfg(test)]
30mod test {
31    use super::*;
32
33    #[test]
34    fn json() -> serde_json::Result<()> {
35        assert!(serde_json::from_str::<ContextType>("0").is_err());
36        assert!(serde_json::from_str::<ContextType>("500").is_err());
37
38        let json = "[1,2,3,501]";
39        let e1: Vec<ContextType> = serde_json::from_str(json)?;
40        assert_eq!(serde_json::to_string(&e1)?, json);
41        assert_eq!(
42            e1,
43            vec![
44                ContextType::Content,
45                ContextType::Social,
46                ContextType::Product,
47                ContextType::ExchangeSpecific(501),
48            ]
49        );
50
51        Ok(())
52    }
53}