sheave_core/messages/play/
play_mode.rs1use std::cmp::Ordering;
2use crate::messages::amf::v0::Number;
3
4#[repr(i64)]
17#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
18pub enum PlayMode {
19 Other = i64::MIN,
20 #[default]
21 Both = -2,
22 Live,
23 Record
24}
25
26impl From<i64> for PlayMode {
27 fn from(play_mode: i64) -> Self {
28 use PlayMode::*;
29
30 match play_mode {
31 -2 => Both,
32 -1 => Live,
33 play_mode if play_mode >= 0 => Record,
34 _ => Other
35 }
36 }
37}
38
39impl From<PlayMode> for i64 {
40 fn from(play_mode: PlayMode) -> Self {
41 play_mode as i64
42 }
43}
44
45impl From<Number> for PlayMode {
46 fn from(play_mode: Number) -> Self {
47 Self::from(play_mode.as_signed_integer())
48 }
49}
50
51impl From<PlayMode> for Number {
52 fn from(play_mode: PlayMode) -> Self {
53 Self::new(play_mode as i64 as f64)
54 }
55}
56
57impl PartialEq<i64> for PlayMode {
58 fn eq(&self, other: &i64) -> bool {
59 i64::from(*self).eq(other)
60 }
61}
62
63impl PartialOrd<i64> for PlayMode {
64 fn partial_cmp(&self, other: &i64) -> Option<Ordering> {
65 i64::from(*self).partial_cmp(other)
66 }
67}
68
69impl PartialEq<PlayMode> for i64 {
70 fn eq(&self, other: &PlayMode) -> bool {
71 self.eq(&(*other as i64))
72 }
73}
74
75impl PartialOrd<PlayMode> for i64 {
76 fn partial_cmp(&self, other: &PlayMode) -> Option<Ordering> {
77 self.partial_cmp(&(*other as i64))
78 }
79}