itunes_com/wrappers/
types.rs1use std::marker::PhantomData;
2
3use windows::Win32::System::Com::VARIANT;
4
5
6pub type PersistentId = u64;
7
8
9pub struct Variant<'a, T: 'a> {
11 inner: VARIANT,
12 lifetime: PhantomData<&'a T>,
13}
14
15impl<'a, T> Variant<'a, T> {
16 pub(crate) fn new(inner: VARIANT) -> Self {
17 Self { inner, lifetime: PhantomData }
18 }
19
20 pub fn as_raw(&self) -> &VARIANT {
22 &self.inner
23 }
24}
25
26pub enum Rating {
28 None,
30 One,
32 Two,
34 Three,
36 Four,
38 Five,
40}
41
42impl Rating {
43 pub fn from_stars(stars: Option<u8>) -> Self {
47 match stars {
48 Some(1) => Self::One,
49 Some(2) => Self::Two,
50 Some(3) => Self::Three,
51 Some(4) => Self::Four,
52 Some(5) => Self::Five,
53 _ => Self::None,
54 }
55 }
56
57 pub fn stars(&self) -> Option<u8> {
59 match self {
60 Rating::None => None,
61 Rating::One => Some(1),
62 Rating::Two => Some(2),
63 Rating::Three => Some(3),
64 Rating::Four => Some(4),
65 Rating::Five => Some(5),
66 }
67 }
68}
69
70impl std::convert::From<super::LONG> for Rating {
72 fn from(long: super::LONG) -> Rating {
73 match long {
74 0..=19 => Rating::None,
75 20..=39 => Rating::One,
76 40..=59 => Rating::Two,
77 60..=79 => Rating::Three,
78 80..=99 => Rating::Four,
79 100.. => Rating::Five,
80 _ => Rating::None,
82 }
83 }
84}
85
86impl std::convert::From<Rating> for super::LONG {
87 fn from(rating: Rating) -> super::LONG {
88 match rating {
89 Rating::None => 0,
90 Rating::One => 20,
91 Rating::Two => 40,
92 Rating::Three => 60,
93 Rating::Four => 80,
94 Rating::Five => 100,
95 }
96 }
97}