Skip to main content

lastfm_client/types/
period.rs

1/// Period options for Last.fm time range filters
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3#[non_exhaustive]
4pub enum Period {
5    /// All-time (no time limit)
6    Overall,
7    /// Last 7 days
8    Week,
9    /// Last 30 days
10    Month,
11    /// Last 3 months
12    ThreeMonth,
13    /// Last 6 months
14    SixMonth,
15    /// Last 12 months
16    TwelveMonth,
17}
18
19impl Period {}
20
21/// Track limit options
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23#[non_exhaustive]
24pub enum TrackLimit {
25    /// Fetch up to the specified number of items
26    Limited(u32),
27    /// Fetch all available items
28    Unlimited,
29}
30
31impl From<Option<u32>> for TrackLimit {
32    fn from(opt: Option<u32>) -> Self {
33        opt.map_or(Self::Unlimited, Self::Limited)
34    }
35}
36
37impl From<u32> for TrackLimit {
38    fn from(limit: u32) -> Self {
39        Self::Limited(limit)
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_track_limit_from_option() {
49        let limited: TrackLimit = Some(100).into();
50        assert_eq!(limited, TrackLimit::Limited(100));
51
52        let unlimited: TrackLimit = None.into();
53        assert_eq!(unlimited, TrackLimit::Unlimited);
54    }
55
56    #[test]
57    fn test_track_limit_from_u32() {
58        let limited: TrackLimit = 50.into();
59        assert_eq!(limited, TrackLimit::Limited(50));
60    }
61}