Skip to main content

lastfm_rs/model/
mod.rs

1//! Last.fm Data Models
2//!
3//! These are the various models the crate uses throughout the library, centralized
4//! in this file to ease development and remove code duplication.
5
6use chrono::{DateTime, Utc};
7use serde::Deserialize;
8
9use crate::utilities::deserialize_datetime_from_str;
10
11/// Various attributes transmitted by several API endpoints.
12#[derive(Debug, Deserialize)]
13pub struct Attributes {
14    /// The given Page currently paginated in the API.
15    pub page: String,
16    /// The total amount of items.
17    pub total: String,
18    /// The user associated with the given item.
19    pub user: String,
20    /// The amount of items listed in a single page.
21    #[serde(rename = "perPage")]
22    pub per_page: String,
23    /// The total amount of Pages available to paginate.
24    #[serde(rename = "totalPages")]
25    pub total_pages: String,
26}
27
28/// The Date object. Consists of a raw UTC date (able to be formatted), and an already
29/// formatted date string ready to be used. The raw date uses the chrono date & time
30/// library to format the date.
31#[derive(Debug, Deserialize)]
32pub struct TrackDate {
33    /// The date of when the given Track was scrobbled or loved, in UTC.
34    ///
35    /// This is not formatted by default, meaning you will have to format
36    /// this yourself.
37    #[serde(rename = "uts")]
38    #[serde(deserialize_with = "deserialize_datetime_from_str")]
39    pub raw_date: DateTime<Utc>,
40    /// The date of when the given Track was scrobbled or loved, formatted in the
41    /// `%d %b %Y, %H:%M` date format, e.g. "11 Dec 2020, 23:12".
42    #[serde(rename = "#text")]
43    pub formatted_date: String,
44}
45
46/// The Image structure. Contains a couple fields solely related to images
47/// such as the image's size, and a link to the image hosted on Last.fm's
48/// content delivery network.
49#[derive(Debug, Deserialize)]
50pub struct Image {
51    /// The size of the image. Can be small, medium, or large.
52    #[serde(rename = "size")]
53    pub image_size: String,
54    /// A URL to the image, hosted on Last.fm's content delivery network.
55    #[serde(rename = "#text")]
56    pub image_url: String,
57}