yamuse 0.2.0

typed async client for the yandex music api: catalogue, likes, playlists, radio, lossless downloads and ynison realtime
Documentation
//! small standalone models: trailers and tag results.

use serde::{Deserialize, Serialize};
use serde_json::Value;

use super::track::Track;

/// a trailer: a titled selection of tracks.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct TrailerInfo {
    /// trailer title.
    pub title: Option<String>,
    /// trailer tracks.
    pub tracks: Vec<Track>,
}

/// the playlists grouped under a tag.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub struct TagResult {
    /// the tag descriptor, still free-form upstream.
    pub tag: Option<Value>,
    /// ids of the tagged playlists, as `uid:kind` strings.
    pub ids: Vec<String>,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn misc_models_survive_an_empty_object() {
        serde_json::from_str::<TrailerInfo>("{}").unwrap();
        serde_json::from_str::<TagResult>("{}").unwrap();
    }

    #[test]
    fn tag_results_carry_playlist_ids() {
        let result: TagResult =
            serde_json::from_str(r#"{"tag":{"id":"rock"},"ids":["1:2","3:4"]}"#).unwrap();
        assert_eq!(result.ids, vec!["1:2", "3:4"]);
        assert!(result.tag.is_some());
    }
}