openrtb2/
playback_method.rs

1use serde_repr::{Deserialize_repr, Serialize_repr};
2
3/// 5.10 Playback Methods
4///
5/// The following table lists the various playback methods.
6#[derive(Serialize_repr, Deserialize_repr, Debug, PartialEq, Eq, Clone, Copy)]
7#[repr(i32)]
8pub enum PlaybackMethod {
9    /// Initiates on Page Load with Sound On
10    AutoPlaySoundOn = 1,
11    /// Initiates on Page Load with Sound Off by Default
12    AutoPlaySoundOff,
13    /// Initiates on Click with Sound On
14    ClickToPlay,
15    /// Initiates on Mouse-Over with Sound On
16    MouseOver,
17    /// Initiates on Entering Viewport with Sound On
18    EnterSoundOn,
19    /// Initiates on Entering Viewport with Sound Off by Default
20    EnterSoundOff,
21}
22
23#[cfg(test)]
24mod test {
25    use super::*;
26
27    #[test]
28    fn json() -> serde_json::Result<()> {
29        assert!(serde_json::from_str::<PlaybackMethod>("-1").is_err());
30
31        let json = "[1,2]";
32        let e1: Vec<PlaybackMethod> = serde_json::from_str(json)?;
33        assert_eq!(
34            e1,
35            vec![
36                PlaybackMethod::AutoPlaySoundOn,
37                PlaybackMethod::AutoPlaySoundOff
38            ]
39        );
40        assert_eq!(serde_json::to_string(&e1)?, json);
41
42        Ok(())
43    }
44}