mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Merge pull request #1037 from dnlmlr/metadata-wrappers-deref-mut
Implement `DerefMut` for wrapper types in metadata
This commit is contained in:
commit
ebfe8ca36c
19 changed files with 164 additions and 271 deletions
|
@ -1,13 +1,21 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
artist::Artists, availability::Availabilities, copyright::Copyrights, external_id::ExternalIds,
|
artist::Artists,
|
||||||
image::Images, request::RequestResult, restriction::Restrictions, sale_period::SalePeriods,
|
availability::Availabilities,
|
||||||
track::Tracks, util::try_from_repeated_message, Metadata,
|
copyright::Copyrights,
|
||||||
|
external_id::ExternalIds,
|
||||||
|
image::Images,
|
||||||
|
request::RequestResult,
|
||||||
|
restriction::Restrictions,
|
||||||
|
sale_period::SalePeriods,
|
||||||
|
track::Tracks,
|
||||||
|
util::{impl_deref_wrapped, impl_try_from_repeated},
|
||||||
|
Metadata,
|
||||||
};
|
};
|
||||||
|
|
||||||
use librespot_core::{date::Date, Error, Session, SpotifyId};
|
use librespot_core::{date::Date, Error, Session, SpotifyId};
|
||||||
|
@ -44,12 +52,7 @@ pub struct Album {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Albums(pub Vec<SpotifyId>);
|
pub struct Albums(pub Vec<SpotifyId>);
|
||||||
|
|
||||||
impl Deref for Albums {
|
impl_deref_wrapped!(Albums, Vec<SpotifyId>);
|
||||||
type Target = Vec<SpotifyId>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Disc {
|
pub struct Disc {
|
||||||
|
@ -61,12 +64,7 @@ pub struct Disc {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Discs(pub Vec<Disc>);
|
pub struct Discs(pub Vec<Disc>);
|
||||||
|
|
||||||
impl Deref for Discs {
|
impl_deref_wrapped!(Discs, Vec<Disc>);
|
||||||
type Target = Vec<Disc>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Album {
|
impl Album {
|
||||||
pub fn tracks(&self) -> Tracks {
|
pub fn tracks(&self) -> Tracks {
|
||||||
|
@ -121,7 +119,7 @@ impl TryFrom<&<Self as Metadata>::Message> for Album {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(<Album as Metadata>::Message, Albums);
|
impl_try_from_repeated!(<Album as Metadata>::Message, Albums);
|
||||||
|
|
||||||
impl TryFrom<&DiscMessage> for Disc {
|
impl TryFrom<&DiscMessage> for Disc {
|
||||||
type Error = librespot_core::Error;
|
type Error = librespot_core::Error;
|
||||||
|
@ -134,4 +132,4 @@ impl TryFrom<&DiscMessage> for Disc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(DiscMessage, Discs);
|
impl_try_from_repeated!(DiscMessage, Discs);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
restriction::Restrictions,
|
restriction::Restrictions,
|
||||||
sale_period::SalePeriods,
|
sale_period::SalePeriods,
|
||||||
track::Tracks,
|
track::Tracks,
|
||||||
util::{from_repeated_message, try_from_repeated_message},
|
util::{impl_deref_wrapped, impl_from_repeated, impl_try_from_repeated},
|
||||||
Metadata,
|
Metadata,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,12 +54,7 @@ pub struct Artist {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Artists(pub Vec<Artist>);
|
pub struct Artists(pub Vec<Artist>);
|
||||||
|
|
||||||
impl Deref for Artists {
|
impl_deref_wrapped!(Artists, Vec<Artist>);
|
||||||
type Target = Vec<Artist>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ArtistWithRole {
|
pub struct ArtistWithRole {
|
||||||
|
@ -71,12 +66,7 @@ pub struct ArtistWithRole {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ArtistsWithRole(pub Vec<ArtistWithRole>);
|
pub struct ArtistsWithRole(pub Vec<ArtistWithRole>);
|
||||||
|
|
||||||
impl Deref for ArtistsWithRole {
|
impl_deref_wrapped!(ArtistsWithRole, Vec<ArtistWithRole>);
|
||||||
type Target = Vec<ArtistWithRole>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TopTracks {
|
pub struct TopTracks {
|
||||||
|
@ -87,22 +77,12 @@ pub struct TopTracks {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct CountryTopTracks(pub Vec<TopTracks>);
|
pub struct CountryTopTracks(pub Vec<TopTracks>);
|
||||||
|
|
||||||
impl Deref for CountryTopTracks {
|
impl_deref_wrapped!(CountryTopTracks, Vec<TopTracks>);
|
||||||
type Target = Vec<TopTracks>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct AlbumGroup(pub Albums);
|
pub struct AlbumGroup(pub Albums);
|
||||||
|
|
||||||
impl Deref for AlbumGroup {
|
impl_deref_wrapped!(AlbumGroup, Albums);
|
||||||
type Target = Albums;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `AlbumGroups` contains collections of album variants (different releases of the same album).
|
/// `AlbumGroups` contains collections of album variants (different releases of the same album).
|
||||||
/// Ignoring the wrapping types it is structured roughly like this:
|
/// Ignoring the wrapping types it is structured roughly like this:
|
||||||
|
@ -116,12 +96,7 @@ impl Deref for AlbumGroup {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct AlbumGroups(pub Vec<AlbumGroup>);
|
pub struct AlbumGroups(pub Vec<AlbumGroup>);
|
||||||
|
|
||||||
impl Deref for AlbumGroups {
|
impl_deref_wrapped!(AlbumGroups, Vec<AlbumGroup>);
|
||||||
type Target = Vec<AlbumGroup>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Biography {
|
pub struct Biography {
|
||||||
|
@ -133,12 +108,7 @@ pub struct Biography {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Biographies(pub Vec<Biography>);
|
pub struct Biographies(pub Vec<Biography>);
|
||||||
|
|
||||||
impl Deref for Biographies {
|
impl_deref_wrapped!(Biographies, Vec<Biography>);
|
||||||
type Target = Vec<Biography>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ActivityPeriod {
|
pub struct ActivityPeriod {
|
||||||
|
@ -150,12 +120,7 @@ pub struct ActivityPeriod {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ActivityPeriods(pub Vec<ActivityPeriod>);
|
pub struct ActivityPeriods(pub Vec<ActivityPeriod>);
|
||||||
|
|
||||||
impl Deref for ActivityPeriods {
|
impl_deref_wrapped!(ActivityPeriods, Vec<ActivityPeriod>);
|
||||||
type Target = Vec<ActivityPeriod>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CountryTopTracks {
|
impl CountryTopTracks {
|
||||||
pub fn for_country(&self, country: &str) -> Tracks {
|
pub fn for_country(&self, country: &str) -> Tracks {
|
||||||
|
@ -242,7 +207,7 @@ impl TryFrom<&<Self as Metadata>::Message> for Artist {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(<Artist as Metadata>::Message, Artists);
|
impl_try_from_repeated!(<Artist as Metadata>::Message, Artists);
|
||||||
|
|
||||||
impl TryFrom<&ArtistWithRoleMessage> for ArtistWithRole {
|
impl TryFrom<&ArtistWithRoleMessage> for ArtistWithRole {
|
||||||
type Error = librespot_core::Error;
|
type Error = librespot_core::Error;
|
||||||
|
@ -255,7 +220,7 @@ impl TryFrom<&ArtistWithRoleMessage> for ArtistWithRole {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(ArtistWithRoleMessage, ArtistsWithRole);
|
impl_try_from_repeated!(ArtistWithRoleMessage, ArtistsWithRole);
|
||||||
|
|
||||||
impl TryFrom<&TopTracksMessage> for TopTracks {
|
impl TryFrom<&TopTracksMessage> for TopTracks {
|
||||||
type Error = librespot_core::Error;
|
type Error = librespot_core::Error;
|
||||||
|
@ -267,7 +232,7 @@ impl TryFrom<&TopTracksMessage> for TopTracks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(TopTracksMessage, CountryTopTracks);
|
impl_try_from_repeated!(TopTracksMessage, CountryTopTracks);
|
||||||
|
|
||||||
impl TryFrom<&AlbumGroupMessage> for AlbumGroup {
|
impl TryFrom<&AlbumGroupMessage> for AlbumGroup {
|
||||||
type Error = librespot_core::Error;
|
type Error = librespot_core::Error;
|
||||||
|
@ -290,7 +255,7 @@ impl AlbumGroups {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(AlbumGroupMessage, AlbumGroups);
|
impl_try_from_repeated!(AlbumGroupMessage, AlbumGroups);
|
||||||
|
|
||||||
impl From<&BiographyMessage> for Biography {
|
impl From<&BiographyMessage> for Biography {
|
||||||
fn from(biography: &BiographyMessage) -> Self {
|
fn from(biography: &BiographyMessage) -> Self {
|
||||||
|
@ -308,7 +273,7 @@ impl From<&BiographyMessage> for Biography {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from_repeated_message!(BiographyMessage, Biographies);
|
impl_from_repeated!(BiographyMessage, Biographies);
|
||||||
|
|
||||||
impl From<&ActivityPeriodMessage> for ActivityPeriod {
|
impl From<&ActivityPeriodMessage> for ActivityPeriod {
|
||||||
fn from(activity_periode: &ActivityPeriodMessage) -> Self {
|
fn from(activity_periode: &ActivityPeriodMessage) -> Self {
|
||||||
|
@ -320,4 +285,4 @@ impl From<&ActivityPeriodMessage> for ActivityPeriod {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from_repeated_message!(ActivityPeriodMessage, ActivityPeriods);
|
impl_from_repeated!(ActivityPeriodMessage, ActivityPeriods);
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
use std::{collections::HashMap, fmt::Debug, ops::Deref};
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
fmt::Debug,
|
||||||
|
ops::{Deref, DerefMut},
|
||||||
|
};
|
||||||
|
|
||||||
use librespot_core::FileId;
|
use librespot_core::FileId;
|
||||||
|
|
||||||
|
@ -6,15 +10,12 @@ use librespot_protocol as protocol;
|
||||||
use protocol::metadata::AudioFile as AudioFileMessage;
|
use protocol::metadata::AudioFile as AudioFileMessage;
|
||||||
pub use protocol::metadata::AudioFile_Format as AudioFileFormat;
|
pub use protocol::metadata::AudioFile_Format as AudioFileFormat;
|
||||||
|
|
||||||
|
use crate::util::impl_deref_wrapped;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct AudioFiles(pub HashMap<AudioFileFormat, FileId>);
|
pub struct AudioFiles(pub HashMap<AudioFileFormat, FileId>);
|
||||||
|
|
||||||
impl Deref for AudioFiles {
|
impl_deref_wrapped!(AudioFiles, HashMap<AudioFileFormat, FileId>);
|
||||||
type Target = HashMap<AudioFileFormat, FileId>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AudioFiles {
|
impl AudioFiles {
|
||||||
pub fn is_ogg_vorbis(format: AudioFileFormat) -> bool {
|
pub fn is_ogg_vorbis(format: AudioFileFormat) -> bool {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::util::try_from_repeated_message;
|
use crate::util::{impl_deref_wrapped, impl_try_from_repeated};
|
||||||
|
|
||||||
use librespot_core::date::Date;
|
use librespot_core::date::Date;
|
||||||
|
|
||||||
|
@ -24,12 +24,7 @@ pub struct Availability {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Availabilities(pub Vec<Availability>);
|
pub struct Availabilities(pub Vec<Availability>);
|
||||||
|
|
||||||
impl Deref for Availabilities {
|
impl_deref_wrapped!(Availabilities, Vec<Availability>);
|
||||||
type Target = Vec<Availability>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Error)]
|
#[derive(Debug, Copy, Clone, Error)]
|
||||||
pub enum UnavailabilityReason {
|
pub enum UnavailabilityReason {
|
||||||
|
@ -53,4 +48,4 @@ impl TryFrom<&AvailabilityMessage> for Availability {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(AvailabilityMessage, Availabilities);
|
impl_try_from_repeated!(AvailabilityMessage, Availabilities);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use std::{fmt::Debug, ops::Deref};
|
use std::{
|
||||||
|
fmt::Debug,
|
||||||
|
ops::{Deref, DerefMut},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::util::from_repeated_message;
|
use crate::util::{impl_deref_wrapped, impl_from_repeated};
|
||||||
|
|
||||||
use librespot_protocol as protocol;
|
use librespot_protocol as protocol;
|
||||||
use protocol::metadata::ContentRating as ContentRatingMessage;
|
use protocol::metadata::ContentRating as ContentRatingMessage;
|
||||||
|
@ -14,12 +17,7 @@ pub struct ContentRating {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ContentRatings(pub Vec<ContentRating>);
|
pub struct ContentRatings(pub Vec<ContentRating>);
|
||||||
|
|
||||||
impl Deref for ContentRatings {
|
impl_deref_wrapped!(ContentRatings, Vec<ContentRating>);
|
||||||
type Target = Vec<ContentRating>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&ContentRatingMessage> for ContentRating {
|
impl From<&ContentRatingMessage> for ContentRating {
|
||||||
fn from(content_rating: &ContentRatingMessage) -> Self {
|
fn from(content_rating: &ContentRatingMessage) -> Self {
|
||||||
|
@ -30,4 +28,4 @@ impl From<&ContentRatingMessage> for ContentRating {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from_repeated_message!(ContentRatingMessage, ContentRatings);
|
impl_from_repeated!(ContentRatingMessage, ContentRatings);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use std::{fmt::Debug, ops::Deref};
|
use std::{
|
||||||
|
fmt::Debug,
|
||||||
|
ops::{Deref, DerefMut},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::util::from_repeated_message;
|
use crate::util::{impl_deref_wrapped, impl_from_repeated};
|
||||||
|
|
||||||
use librespot_protocol as protocol;
|
use librespot_protocol as protocol;
|
||||||
use protocol::metadata::Copyright as CopyrightMessage;
|
use protocol::metadata::Copyright as CopyrightMessage;
|
||||||
|
@ -15,12 +18,7 @@ pub struct Copyright {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Copyrights(pub Vec<Copyright>);
|
pub struct Copyrights(pub Vec<Copyright>);
|
||||||
|
|
||||||
impl Deref for Copyrights {
|
impl_deref_wrapped!(Copyrights, Vec<Copyright>);
|
||||||
type Target = Vec<Copyright>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&CopyrightMessage> for Copyright {
|
impl From<&CopyrightMessage> for Copyright {
|
||||||
fn from(copyright: &CopyrightMessage) -> Self {
|
fn from(copyright: &CopyrightMessage) -> Self {
|
||||||
|
@ -31,4 +29,4 @@ impl From<&CopyrightMessage> for Copyright {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from_repeated_message!(CopyrightMessage, Copyrights);
|
impl_from_repeated!(CopyrightMessage, Copyrights);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -14,7 +14,7 @@ use crate::{
|
||||||
image::Images,
|
image::Images,
|
||||||
request::RequestResult,
|
request::RequestResult,
|
||||||
restriction::Restrictions,
|
restriction::Restrictions,
|
||||||
util::try_from_repeated_message,
|
util::{impl_deref_wrapped, impl_try_from_repeated},
|
||||||
video::VideoFiles,
|
video::VideoFiles,
|
||||||
Metadata,
|
Metadata,
|
||||||
};
|
};
|
||||||
|
@ -55,12 +55,7 @@ pub struct Episode {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Episodes(pub Vec<SpotifyId>);
|
pub struct Episodes(pub Vec<SpotifyId>);
|
||||||
|
|
||||||
impl Deref for Episodes {
|
impl_deref_wrapped!(Episodes, Vec<SpotifyId>);
|
||||||
type Target = Vec<SpotifyId>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl InnerAudioItem for Episode {
|
impl InnerAudioItem for Episode {
|
||||||
|
@ -130,4 +125,4 @@ impl TryFrom<&<Self as Metadata>::Message> for Episode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(<Episode as Metadata>::Message, Episodes);
|
impl_try_from_repeated!(<Episode as Metadata>::Message, Episodes);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use std::{fmt::Debug, ops::Deref};
|
use std::{
|
||||||
|
fmt::Debug,
|
||||||
|
ops::{Deref, DerefMut},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::util::from_repeated_message;
|
use crate::util::{impl_deref_wrapped, impl_from_repeated};
|
||||||
|
|
||||||
use librespot_protocol as protocol;
|
use librespot_protocol as protocol;
|
||||||
use protocol::metadata::ExternalId as ExternalIdMessage;
|
use protocol::metadata::ExternalId as ExternalIdMessage;
|
||||||
|
@ -14,12 +17,7 @@ pub struct ExternalId {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ExternalIds(pub Vec<ExternalId>);
|
pub struct ExternalIds(pub Vec<ExternalId>);
|
||||||
|
|
||||||
impl Deref for ExternalIds {
|
impl_deref_wrapped!(ExternalIds, Vec<ExternalId>);
|
||||||
type Target = Vec<ExternalId>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&ExternalIdMessage> for ExternalId {
|
impl From<&ExternalIdMessage> for ExternalId {
|
||||||
fn from(external_id: &ExternalIdMessage) -> Self {
|
fn from(external_id: &ExternalIdMessage) -> Self {
|
||||||
|
@ -30,4 +28,4 @@ impl From<&ExternalIdMessage> for ExternalId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from_repeated_message!(ExternalIdMessage, ExternalIds);
|
impl_from_repeated!(ExternalIdMessage, ExternalIds);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::util::{from_repeated_message, try_from_repeated_message};
|
use crate::util::{impl_deref_wrapped, impl_from_repeated, impl_try_from_repeated};
|
||||||
|
|
||||||
use librespot_core::{FileId, SpotifyId};
|
use librespot_core::{FileId, SpotifyId};
|
||||||
|
|
||||||
|
@ -25,12 +25,7 @@ pub struct Image {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Images(pub Vec<Image>);
|
pub struct Images(pub Vec<Image>);
|
||||||
|
|
||||||
impl Deref for Images {
|
impl_deref_wrapped!(Images, Vec<Image>);
|
||||||
type Target = Vec<Image>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PictureSize {
|
pub struct PictureSize {
|
||||||
|
@ -41,12 +36,7 @@ pub struct PictureSize {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct PictureSizes(pub Vec<PictureSize>);
|
pub struct PictureSizes(pub Vec<PictureSize>);
|
||||||
|
|
||||||
impl Deref for PictureSizes {
|
impl_deref_wrapped!(PictureSizes, Vec<PictureSize>);
|
||||||
type Target = Vec<PictureSize>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TranscodedPicture {
|
pub struct TranscodedPicture {
|
||||||
|
@ -57,12 +47,7 @@ pub struct TranscodedPicture {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TranscodedPictures(pub Vec<TranscodedPicture>);
|
pub struct TranscodedPictures(pub Vec<TranscodedPicture>);
|
||||||
|
|
||||||
impl Deref for TranscodedPictures {
|
impl_deref_wrapped!(TranscodedPictures, Vec<TranscodedPicture>);
|
||||||
type Target = Vec<TranscodedPicture>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&ImageMessage> for Image {
|
impl From<&ImageMessage> for Image {
|
||||||
fn from(image: &ImageMessage) -> Self {
|
fn from(image: &ImageMessage) -> Self {
|
||||||
|
@ -75,7 +60,7 @@ impl From<&ImageMessage> for Image {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from_repeated_message!(ImageMessage, Images);
|
impl_from_repeated!(ImageMessage, Images);
|
||||||
|
|
||||||
impl From<&PictureSizeMessage> for PictureSize {
|
impl From<&PictureSizeMessage> for PictureSize {
|
||||||
fn from(size: &PictureSizeMessage) -> Self {
|
fn from(size: &PictureSizeMessage) -> Self {
|
||||||
|
@ -86,7 +71,7 @@ impl From<&PictureSizeMessage> for PictureSize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from_repeated_message!(PictureSizeMessage, PictureSizes);
|
impl_from_repeated!(PictureSizeMessage, PictureSizes);
|
||||||
|
|
||||||
impl TryFrom<&TranscodedPictureMessage> for TranscodedPicture {
|
impl TryFrom<&TranscodedPictureMessage> for TranscodedPicture {
|
||||||
type Error = librespot_core::Error;
|
type Error = librespot_core::Error;
|
||||||
|
@ -98,4 +83,4 @@ impl TryFrom<&TranscodedPictureMessage> for TranscodedPicture {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(TranscodedPictureMessage, TranscodedPictures);
|
impl_try_from_repeated!(TranscodedPictureMessage, TranscodedPictures);
|
||||||
|
|
|
@ -2,10 +2,13 @@ use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{image::PictureSizes, util::from_repeated_enum};
|
use crate::{
|
||||||
|
image::PictureSizes,
|
||||||
|
util::{impl_deref_wrapped, impl_from_repeated_copy},
|
||||||
|
};
|
||||||
|
|
||||||
use librespot_core::date::Date;
|
use librespot_core::date::Date;
|
||||||
|
|
||||||
|
@ -37,24 +40,14 @@ pub struct PlaylistAttributes {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct PlaylistAttributeKinds(pub Vec<PlaylistAttributeKind>);
|
pub struct PlaylistAttributeKinds(pub Vec<PlaylistAttributeKind>);
|
||||||
|
|
||||||
impl Deref for PlaylistAttributeKinds {
|
impl_deref_wrapped!(PlaylistAttributeKinds, Vec<PlaylistAttributeKind>);
|
||||||
type Target = Vec<PlaylistAttributeKind>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
from_repeated_enum!(PlaylistAttributeKind, PlaylistAttributeKinds);
|
impl_from_repeated_copy!(PlaylistAttributeKind, PlaylistAttributeKinds);
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct PlaylistFormatAttribute(pub HashMap<String, String>);
|
pub struct PlaylistFormatAttribute(pub HashMap<String, String>);
|
||||||
|
|
||||||
impl Deref for PlaylistFormatAttribute {
|
impl_deref_wrapped!(PlaylistFormatAttribute, HashMap<String, String>);
|
||||||
type Target = HashMap<String, String>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PlaylistItemAttributes {
|
pub struct PlaylistItemAttributes {
|
||||||
|
@ -69,14 +62,9 @@ pub struct PlaylistItemAttributes {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct PlaylistItemAttributeKinds(pub Vec<PlaylistItemAttributeKind>);
|
pub struct PlaylistItemAttributeKinds(pub Vec<PlaylistItemAttributeKind>);
|
||||||
|
|
||||||
impl Deref for PlaylistItemAttributeKinds {
|
impl_deref_wrapped!(PlaylistItemAttributeKinds, Vec<PlaylistItemAttributeKind>);
|
||||||
type Target = Vec<PlaylistItemAttributeKind>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
from_repeated_enum!(PlaylistItemAttributeKind, PlaylistItemAttributeKinds);
|
impl_from_repeated_copy!(PlaylistItemAttributeKind, PlaylistItemAttributeKinds);
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PlaylistPartialAttributes {
|
pub struct PlaylistPartialAttributes {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::util::try_from_repeated_message;
|
use crate::util::{impl_deref_wrapped, impl_try_from_repeated};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
attribute::{PlaylistAttributes, PlaylistItemAttributes},
|
attribute::{PlaylistAttributes, PlaylistItemAttributes},
|
||||||
|
@ -27,12 +27,7 @@ pub struct PlaylistItem {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct PlaylistItems(pub Vec<PlaylistItem>);
|
pub struct PlaylistItems(pub Vec<PlaylistItem>);
|
||||||
|
|
||||||
impl Deref for PlaylistItems {
|
impl_deref_wrapped!(PlaylistItems, Vec<PlaylistItem>);
|
||||||
type Target = Vec<PlaylistItem>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PlaylistItemList {
|
pub struct PlaylistItemList {
|
||||||
|
@ -56,12 +51,7 @@ pub struct PlaylistMetaItem {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct PlaylistMetaItems(pub Vec<PlaylistMetaItem>);
|
pub struct PlaylistMetaItems(pub Vec<PlaylistMetaItem>);
|
||||||
|
|
||||||
impl Deref for PlaylistMetaItems {
|
impl_deref_wrapped!(PlaylistMetaItems, Vec<PlaylistMetaItem>);
|
||||||
type Target = Vec<PlaylistMetaItem>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<&PlaylistItemMessage> for PlaylistItem {
|
impl TryFrom<&PlaylistItemMessage> for PlaylistItem {
|
||||||
type Error = librespot_core::Error;
|
type Error = librespot_core::Error;
|
||||||
|
@ -73,7 +63,7 @@ impl TryFrom<&PlaylistItemMessage> for PlaylistItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(PlaylistItemMessage, PlaylistItems);
|
impl_try_from_repeated!(PlaylistItemMessage, PlaylistItems);
|
||||||
|
|
||||||
impl TryFrom<&PlaylistItemsMessage> for PlaylistItemList {
|
impl TryFrom<&PlaylistItemsMessage> for PlaylistItemList {
|
||||||
type Error = librespot_core::Error;
|
type Error = librespot_core::Error;
|
||||||
|
@ -102,4 +92,4 @@ impl TryFrom<&PlaylistMetaItemMessage> for PlaylistMetaItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(PlaylistMetaItemMessage, PlaylistMetaItems);
|
impl_try_from_repeated!(PlaylistMetaItemMessage, PlaylistMetaItems);
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use protobuf::Message;
|
use protobuf::Message;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
request::{MercuryRequest, RequestResult},
|
request::{MercuryRequest, RequestResult},
|
||||||
util::{from_repeated_enum, try_from_repeated_message},
|
util::{impl_deref_wrapped, impl_from_repeated_copy, impl_try_from_repeated},
|
||||||
Metadata,
|
Metadata,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,12 +29,7 @@ use protocol::playlist4_external::GeoblockBlockingType as Geoblock;
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Geoblocks(Vec<Geoblock>);
|
pub struct Geoblocks(Vec<Geoblock>);
|
||||||
|
|
||||||
impl Deref for Geoblocks {
|
impl_deref_wrapped!(Geoblocks, Vec<Geoblock>);
|
||||||
type Target = Vec<Geoblock>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Playlist {
|
pub struct Playlist {
|
||||||
|
@ -58,22 +53,12 @@ pub struct Playlist {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Playlists(pub Vec<SpotifyId>);
|
pub struct Playlists(pub Vec<SpotifyId>);
|
||||||
|
|
||||||
impl Deref for Playlists {
|
impl_deref_wrapped!(Playlists, Vec<SpotifyId>);
|
||||||
type Target = Vec<SpotifyId>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct RootPlaylist(pub SelectedListContent);
|
pub struct RootPlaylist(pub SelectedListContent);
|
||||||
|
|
||||||
impl Deref for RootPlaylist {
|
impl_deref_wrapped!(RootPlaylist, SelectedListContent);
|
||||||
type Target = SelectedListContent;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SelectedListContent {
|
pub struct SelectedListContent {
|
||||||
|
@ -225,5 +210,5 @@ impl TryFrom<&<Playlist as Metadata>::Message> for SelectedListContent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from_repeated_enum!(Geoblock, Geoblocks);
|
impl_from_repeated_copy!(Geoblock, Geoblocks);
|
||||||
try_from_repeated_message!(Vec<u8>, Playlists);
|
impl_try_from_repeated!(Vec<u8>, Playlists);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
attribute::{PlaylistUpdateAttributes, PlaylistUpdateItemAttributes},
|
attribute::{PlaylistUpdateAttributes, PlaylistUpdateItemAttributes},
|
||||||
item::PlaylistItems,
|
item::PlaylistItems,
|
||||||
},
|
},
|
||||||
util::try_from_repeated_message,
|
util::{impl_deref_wrapped, impl_try_from_repeated},
|
||||||
};
|
};
|
||||||
|
|
||||||
use librespot_protocol as protocol;
|
use librespot_protocol as protocol;
|
||||||
|
@ -32,12 +32,7 @@ pub struct PlaylistOperation {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct PlaylistOperations(pub Vec<PlaylistOperation>);
|
pub struct PlaylistOperations(pub Vec<PlaylistOperation>);
|
||||||
|
|
||||||
impl Deref for PlaylistOperations {
|
impl_deref_wrapped!(PlaylistOperations, Vec<PlaylistOperation>);
|
||||||
type Target = Vec<PlaylistOperation>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct PlaylistOperationAdd {
|
pub struct PlaylistOperationAdd {
|
||||||
|
@ -76,7 +71,7 @@ impl TryFrom<&PlaylistOperationMessage> for PlaylistOperation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(PlaylistOperationMessage, PlaylistOperations);
|
impl_try_from_repeated!(PlaylistOperationMessage, PlaylistOperations);
|
||||||
|
|
||||||
impl TryFrom<&PlaylistAddMessage> for PlaylistOperationAdd {
|
impl TryFrom<&PlaylistAddMessage> for PlaylistOperationAdd {
|
||||||
type Error = librespot_core::Error;
|
type Error = librespot_core::Error;
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use std::{fmt::Debug, ops::Deref};
|
use std::{
|
||||||
|
fmt::Debug,
|
||||||
|
ops::{Deref, DerefMut},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::util::from_repeated_enum;
|
use crate::util::{impl_deref_wrapped, impl_from_repeated_copy};
|
||||||
|
|
||||||
use librespot_protocol as protocol;
|
use librespot_protocol as protocol;
|
||||||
use protocol::playlist_permission::Capabilities as CapabilitiesMessage;
|
use protocol::playlist_permission::Capabilities as CapabilitiesMessage;
|
||||||
|
@ -19,12 +22,7 @@ pub struct Capabilities {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct PermissionLevels(pub Vec<PermissionLevel>);
|
pub struct PermissionLevels(pub Vec<PermissionLevel>);
|
||||||
|
|
||||||
impl Deref for PermissionLevels {
|
impl_deref_wrapped!(PermissionLevels, Vec<PermissionLevel>);
|
||||||
type Target = Vec<PermissionLevel>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&CapabilitiesMessage> for Capabilities {
|
impl From<&CapabilitiesMessage> for Capabilities {
|
||||||
fn from(playlist: &CapabilitiesMessage) -> Self {
|
fn from(playlist: &CapabilitiesMessage) -> Self {
|
||||||
|
@ -39,4 +37,4 @@ impl From<&CapabilitiesMessage> for Capabilities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from_repeated_enum!(PermissionLevel, PermissionLevels);
|
impl_from_repeated_copy!(PermissionLevel, PermissionLevels);
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
use std::{fmt::Debug, ops::Deref};
|
use std::{
|
||||||
|
fmt::Debug,
|
||||||
|
ops::{Deref, DerefMut},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::util::{from_repeated_enum, from_repeated_message};
|
use crate::util::impl_deref_wrapped;
|
||||||
|
use crate::util::{impl_from_repeated, impl_from_repeated_copy};
|
||||||
|
|
||||||
use protocol::metadata::Restriction as RestrictionMessage;
|
use protocol::metadata::Restriction as RestrictionMessage;
|
||||||
|
|
||||||
|
@ -20,22 +24,12 @@ pub struct Restriction {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Restrictions(pub Vec<Restriction>);
|
pub struct Restrictions(pub Vec<Restriction>);
|
||||||
|
|
||||||
impl Deref for Restrictions {
|
impl_deref_wrapped!(Restrictions, Vec<Restriction>);
|
||||||
type Target = Vec<Restriction>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct RestrictionCatalogues(pub Vec<RestrictionCatalogue>);
|
pub struct RestrictionCatalogues(pub Vec<RestrictionCatalogue>);
|
||||||
|
|
||||||
impl Deref for RestrictionCatalogues {
|
impl_deref_wrapped!(RestrictionCatalogues, Vec<RestrictionCatalogue>);
|
||||||
type Target = Vec<RestrictionCatalogue>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Restriction {
|
impl Restriction {
|
||||||
fn parse_country_codes(country_codes: &str) -> Vec<String> {
|
fn parse_country_codes(country_codes: &str) -> Vec<String> {
|
||||||
|
@ -74,8 +68,8 @@ impl From<&RestrictionMessage> for Restriction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from_repeated_message!(RestrictionMessage, Restrictions);
|
impl_from_repeated!(RestrictionMessage, Restrictions);
|
||||||
from_repeated_enum!(RestrictionCatalogue, RestrictionCatalogues);
|
impl_from_repeated_copy!(RestrictionCatalogue, RestrictionCatalogues);
|
||||||
|
|
||||||
struct StrChunks<'s>(&'s str, usize);
|
struct StrChunks<'s>(&'s str, usize);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{restriction::Restrictions, util::try_from_repeated_message};
|
use crate::{
|
||||||
|
restriction::Restrictions,
|
||||||
|
util::{impl_deref_wrapped, impl_try_from_repeated},
|
||||||
|
};
|
||||||
|
|
||||||
use librespot_core::date::Date;
|
use librespot_core::date::Date;
|
||||||
|
|
||||||
|
@ -21,12 +24,7 @@ pub struct SalePeriod {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct SalePeriods(pub Vec<SalePeriod>);
|
pub struct SalePeriods(pub Vec<SalePeriod>);
|
||||||
|
|
||||||
impl Deref for SalePeriods {
|
impl_deref_wrapped!(SalePeriods, Vec<SalePeriod>);
|
||||||
type Target = Vec<SalePeriod>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<&SalePeriodMessage> for SalePeriod {
|
impl TryFrom<&SalePeriodMessage> for SalePeriod {
|
||||||
type Error = librespot_core::Error;
|
type Error = librespot_core::Error;
|
||||||
|
@ -39,4 +37,4 @@ impl TryFrom<&SalePeriodMessage> for SalePeriod {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(SalePeriodMessage, SalePeriods);
|
impl_try_from_repeated!(SalePeriodMessage, SalePeriods);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
ops::Deref,
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
external_id::ExternalIds,
|
external_id::ExternalIds,
|
||||||
restriction::Restrictions,
|
restriction::Restrictions,
|
||||||
sale_period::SalePeriods,
|
sale_period::SalePeriods,
|
||||||
util::try_from_repeated_message,
|
util::{impl_deref_wrapped, impl_try_from_repeated},
|
||||||
Album, Metadata, RequestResult,
|
Album, Metadata, RequestResult,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,12 +56,7 @@ pub struct Track {
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Tracks(pub Vec<SpotifyId>);
|
pub struct Tracks(pub Vec<SpotifyId>);
|
||||||
|
|
||||||
impl Deref for Tracks {
|
impl_deref_wrapped!(Tracks, Vec<SpotifyId>);
|
||||||
type Target = Vec<SpotifyId>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl InnerAudioItem for Track {
|
impl InnerAudioItem for Track {
|
||||||
|
@ -146,4 +141,4 @@ impl TryFrom<&<Self as Metadata>::Message> for Track {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try_from_repeated_message!(<Track as Metadata>::Message, Tracks);
|
impl_try_from_repeated!(<Track as Metadata>::Message, Tracks);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
macro_rules! from_repeated_message {
|
macro_rules! impl_from_repeated {
|
||||||
($src:ty, $dst:ty) => {
|
($src:ty, $dst:ty) => {
|
||||||
impl From<&[$src]> for $dst {
|
impl From<&[$src]> for $dst {
|
||||||
fn from(src: &[$src]) -> Self {
|
fn from(src: &[$src]) -> Self {
|
||||||
|
@ -9,22 +9,22 @@ macro_rules! from_repeated_message {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) use from_repeated_message;
|
pub(crate) use impl_from_repeated;
|
||||||
|
|
||||||
macro_rules! from_repeated_enum {
|
macro_rules! impl_from_repeated_copy {
|
||||||
($src:ty, $dst:ty) => {
|
($src:ty, $dst:ty) => {
|
||||||
impl From<&[$src]> for $dst {
|
impl From<&[$src]> for $dst {
|
||||||
fn from(src: &[$src]) -> Self {
|
fn from(src: &[$src]) -> Self {
|
||||||
let result = src.iter().map(|x| <$src>::from(*x)).collect();
|
let result = src.iter().copied().collect();
|
||||||
Self(result)
|
Self(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) use from_repeated_enum;
|
pub(crate) use impl_from_repeated_copy;
|
||||||
|
|
||||||
macro_rules! try_from_repeated_message {
|
macro_rules! impl_try_from_repeated {
|
||||||
($src:ty, $dst:ty) => {
|
($src:ty, $dst:ty) => {
|
||||||
impl TryFrom<&[$src]> for $dst {
|
impl TryFrom<&[$src]> for $dst {
|
||||||
type Error = librespot_core::Error;
|
type Error = librespot_core::Error;
|
||||||
|
@ -36,4 +36,23 @@ macro_rules! try_from_repeated_message {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) use try_from_repeated_message;
|
pub(crate) use impl_try_from_repeated;
|
||||||
|
|
||||||
|
macro_rules! impl_deref_wrapped {
|
||||||
|
($wrapper:ty, $inner:ty) => {
|
||||||
|
impl Deref for $wrapper {
|
||||||
|
type Target = $inner;
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DerefMut for $wrapper {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) use impl_deref_wrapped;
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use std::{fmt::Debug, ops::Deref};
|
use std::{
|
||||||
|
fmt::Debug,
|
||||||
|
ops::{Deref, DerefMut},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::util::from_repeated_message;
|
use crate::util::{impl_deref_wrapped, impl_from_repeated};
|
||||||
|
|
||||||
use librespot_core::FileId;
|
use librespot_core::FileId;
|
||||||
|
|
||||||
|
@ -10,11 +13,6 @@ use protocol::metadata::VideoFile as VideoFileMessage;
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct VideoFiles(pub Vec<FileId>);
|
pub struct VideoFiles(pub Vec<FileId>);
|
||||||
|
|
||||||
impl Deref for VideoFiles {
|
impl_deref_wrapped!(VideoFiles, Vec<FileId>);
|
||||||
type Target = Vec<FileId>;
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
from_repeated_message!(VideoFileMessage, VideoFiles);
|
impl_from_repeated!(VideoFileMessage, VideoFiles);
|
||||||
|
|
Loading…
Reference in a new issue