mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Rename from_repeated_*
functions to impl_*
- `from_repeated_message` -> `impl_from_repeated` - `from_repeated_enum` -> `impl_from_repeated_copy` since the enum references were just simply deref copied - `try_from_repeated_message` -> `impl_try_from_repeated` - Simplified the implementation of `from_repeated_enum`
This commit is contained in:
parent
a7fa0e2299
commit
0c69126065
18 changed files with 53 additions and 53 deletions
|
@ -14,7 +14,7 @@ use crate::{
|
|||
restriction::Restrictions,
|
||||
sale_period::SalePeriods,
|
||||
track::Tracks,
|
||||
util::{impl_deref_wrapped, try_from_repeated_message},
|
||||
util::{impl_deref_wrapped, impl_try_from_repeated},
|
||||
Metadata,
|
||||
};
|
||||
|
||||
|
@ -119,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 {
|
||||
type Error = librespot_core::Error;
|
||||
|
@ -132,4 +132,4 @@ impl TryFrom<&DiscMessage> for Disc {
|
|||
}
|
||||
}
|
||||
|
||||
try_from_repeated_message!(DiscMessage, Discs);
|
||||
impl_try_from_repeated!(DiscMessage, Discs);
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::{
|
|||
restriction::Restrictions,
|
||||
sale_period::SalePeriods,
|
||||
track::Tracks,
|
||||
util::{from_repeated_message, impl_deref_wrapped, try_from_repeated_message},
|
||||
util::{impl_deref_wrapped, impl_from_repeated, impl_try_from_repeated},
|
||||
Metadata,
|
||||
};
|
||||
|
||||
|
@ -207,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 {
|
||||
type Error = librespot_core::Error;
|
||||
|
@ -220,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 {
|
||||
type Error = librespot_core::Error;
|
||||
|
@ -232,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 {
|
||||
type Error = librespot_core::Error;
|
||||
|
@ -255,7 +255,7 @@ impl AlbumGroups {
|
|||
}
|
||||
}
|
||||
|
||||
try_from_repeated_message!(AlbumGroupMessage, AlbumGroups);
|
||||
impl_try_from_repeated!(AlbumGroupMessage, AlbumGroups);
|
||||
|
||||
impl From<&BiographyMessage> for Biography {
|
||||
fn from(biography: &BiographyMessage) -> Self {
|
||||
|
@ -273,7 +273,7 @@ impl From<&BiographyMessage> for Biography {
|
|||
}
|
||||
}
|
||||
|
||||
from_repeated_message!(BiographyMessage, Biographies);
|
||||
impl_from_repeated!(BiographyMessage, Biographies);
|
||||
|
||||
impl From<&ActivityPeriodMessage> for ActivityPeriod {
|
||||
fn from(activity_periode: &ActivityPeriodMessage) -> Self {
|
||||
|
@ -285,4 +285,4 @@ impl From<&ActivityPeriodMessage> for ActivityPeriod {
|
|||
}
|
||||
}
|
||||
|
||||
from_repeated_message!(ActivityPeriodMessage, ActivityPeriods);
|
||||
impl_from_repeated!(ActivityPeriodMessage, ActivityPeriods);
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
|||
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::util::{impl_deref_wrapped, try_from_repeated_message};
|
||||
use crate::util::{impl_deref_wrapped, impl_try_from_repeated};
|
||||
|
||||
use librespot_core::date::Date;
|
||||
|
||||
|
@ -48,4 +48,4 @@ impl TryFrom<&AvailabilityMessage> for Availability {
|
|||
}
|
||||
}
|
||||
|
||||
try_from_repeated_message!(AvailabilityMessage, Availabilities);
|
||||
impl_try_from_repeated!(AvailabilityMessage, Availabilities);
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use crate::util::{from_repeated_message, impl_deref_wrapped};
|
||||
use crate::util::{impl_deref_wrapped, impl_from_repeated};
|
||||
|
||||
use librespot_protocol as protocol;
|
||||
use protocol::metadata::ContentRating as ContentRatingMessage;
|
||||
|
@ -28,4 +28,4 @@ impl From<&ContentRatingMessage> for ContentRating {
|
|||
}
|
||||
}
|
||||
|
||||
from_repeated_message!(ContentRatingMessage, ContentRatings);
|
||||
impl_from_repeated!(ContentRatingMessage, ContentRatings);
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use crate::util::{from_repeated_message, impl_deref_wrapped};
|
||||
use crate::util::{impl_deref_wrapped, impl_from_repeated};
|
||||
|
||||
use librespot_protocol as protocol;
|
||||
use protocol::metadata::Copyright as CopyrightMessage;
|
||||
|
@ -29,4 +29,4 @@ impl From<&CopyrightMessage> for Copyright {
|
|||
}
|
||||
}
|
||||
|
||||
from_repeated_message!(CopyrightMessage, Copyrights);
|
||||
impl_from_repeated!(CopyrightMessage, Copyrights);
|
||||
|
|
|
@ -14,7 +14,7 @@ use crate::{
|
|||
image::Images,
|
||||
request::RequestResult,
|
||||
restriction::Restrictions,
|
||||
util::{impl_deref_wrapped, try_from_repeated_message},
|
||||
util::{impl_deref_wrapped, impl_try_from_repeated},
|
||||
video::VideoFiles,
|
||||
Metadata,
|
||||
};
|
||||
|
@ -125,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);
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use crate::util::{from_repeated_message, impl_deref_wrapped};
|
||||
use crate::util::{impl_deref_wrapped, impl_from_repeated};
|
||||
|
||||
use librespot_protocol as protocol;
|
||||
use protocol::metadata::ExternalId as ExternalIdMessage;
|
||||
|
@ -28,4 +28,4 @@ impl From<&ExternalIdMessage> for ExternalId {
|
|||
}
|
||||
}
|
||||
|
||||
from_repeated_message!(ExternalIdMessage, ExternalIds);
|
||||
impl_from_repeated!(ExternalIdMessage, ExternalIds);
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use crate::util::{from_repeated_message, impl_deref_wrapped, try_from_repeated_message};
|
||||
use crate::util::{impl_deref_wrapped, impl_from_repeated, impl_try_from_repeated};
|
||||
|
||||
use librespot_core::{FileId, SpotifyId};
|
||||
|
||||
|
@ -60,7 +60,7 @@ impl From<&ImageMessage> for Image {
|
|||
}
|
||||
}
|
||||
|
||||
from_repeated_message!(ImageMessage, Images);
|
||||
impl_from_repeated!(ImageMessage, Images);
|
||||
|
||||
impl From<&PictureSizeMessage> for PictureSize {
|
||||
fn from(size: &PictureSizeMessage) -> Self {
|
||||
|
@ -71,7 +71,7 @@ impl From<&PictureSizeMessage> for PictureSize {
|
|||
}
|
||||
}
|
||||
|
||||
from_repeated_message!(PictureSizeMessage, PictureSizes);
|
||||
impl_from_repeated!(PictureSizeMessage, PictureSizes);
|
||||
|
||||
impl TryFrom<&TranscodedPictureMessage> for TranscodedPicture {
|
||||
type Error = librespot_core::Error;
|
||||
|
@ -83,4 +83,4 @@ impl TryFrom<&TranscodedPictureMessage> for TranscodedPicture {
|
|||
}
|
||||
}
|
||||
|
||||
try_from_repeated_message!(TranscodedPictureMessage, TranscodedPictures);
|
||||
impl_try_from_repeated!(TranscodedPictureMessage, TranscodedPictures);
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::{
|
|||
|
||||
use crate::{
|
||||
image::PictureSizes,
|
||||
util::{from_repeated_enum, impl_deref_wrapped},
|
||||
util::{impl_deref_wrapped, impl_from_repeated_copy},
|
||||
};
|
||||
|
||||
use librespot_core::date::Date;
|
||||
|
@ -42,7 +42,7 @@ pub struct PlaylistAttributeKinds(pub Vec<PlaylistAttributeKind>);
|
|||
|
||||
impl_deref_wrapped!(PlaylistAttributeKinds, Vec<PlaylistAttributeKind>);
|
||||
|
||||
from_repeated_enum!(PlaylistAttributeKind, PlaylistAttributeKinds);
|
||||
impl_from_repeated_copy!(PlaylistAttributeKind, PlaylistAttributeKinds);
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct PlaylistFormatAttribute(pub HashMap<String, String>);
|
||||
|
@ -64,7 +64,7 @@ pub struct PlaylistItemAttributeKinds(pub Vec<PlaylistItemAttributeKind>);
|
|||
|
||||
impl_deref_wrapped!(PlaylistItemAttributeKinds, Vec<PlaylistItemAttributeKind>);
|
||||
|
||||
from_repeated_enum!(PlaylistItemAttributeKind, PlaylistItemAttributeKinds);
|
||||
impl_from_repeated_copy!(PlaylistItemAttributeKind, PlaylistItemAttributeKinds);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PlaylistPartialAttributes {
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use crate::util::{impl_deref_wrapped, try_from_repeated_message};
|
||||
use crate::util::{impl_deref_wrapped, impl_try_from_repeated};
|
||||
|
||||
use super::{
|
||||
attribute::{PlaylistAttributes, PlaylistItemAttributes},
|
||||
|
@ -63,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 {
|
||||
type Error = librespot_core::Error;
|
||||
|
@ -92,4 +92,4 @@ impl TryFrom<&PlaylistMetaItemMessage> for PlaylistMetaItem {
|
|||
}
|
||||
}
|
||||
|
||||
try_from_repeated_message!(PlaylistMetaItemMessage, PlaylistMetaItems);
|
||||
impl_try_from_repeated!(PlaylistMetaItemMessage, PlaylistMetaItems);
|
||||
|
|
|
@ -8,7 +8,7 @@ use protobuf::Message;
|
|||
|
||||
use crate::{
|
||||
request::{MercuryRequest, RequestResult},
|
||||
util::{from_repeated_enum, impl_deref_wrapped, try_from_repeated_message},
|
||||
util::{impl_deref_wrapped, impl_from_repeated_copy, impl_try_from_repeated},
|
||||
Metadata,
|
||||
};
|
||||
|
||||
|
@ -210,5 +210,5 @@ impl TryFrom<&<Playlist as Metadata>::Message> for SelectedListContent {
|
|||
}
|
||||
}
|
||||
|
||||
from_repeated_enum!(Geoblock, Geoblocks);
|
||||
try_from_repeated_message!(Vec<u8>, Playlists);
|
||||
impl_from_repeated_copy!(Geoblock, Geoblocks);
|
||||
impl_try_from_repeated!(Vec<u8>, Playlists);
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
|||
attribute::{PlaylistUpdateAttributes, PlaylistUpdateItemAttributes},
|
||||
item::PlaylistItems,
|
||||
},
|
||||
util::{impl_deref_wrapped, try_from_repeated_message},
|
||||
util::{impl_deref_wrapped, impl_try_from_repeated},
|
||||
};
|
||||
|
||||
use librespot_protocol as protocol;
|
||||
|
@ -71,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 {
|
||||
type Error = librespot_core::Error;
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use crate::util::{from_repeated_enum, impl_deref_wrapped};
|
||||
use crate::util::{impl_deref_wrapped, impl_from_repeated_copy};
|
||||
|
||||
use librespot_protocol as protocol;
|
||||
use protocol::playlist_permission::Capabilities as CapabilitiesMessage;
|
||||
|
@ -37,4 +37,4 @@ impl From<&CapabilitiesMessage> for Capabilities {
|
|||
}
|
||||
}
|
||||
|
||||
from_repeated_enum!(PermissionLevel, PermissionLevels);
|
||||
impl_from_repeated_copy!(PermissionLevel, PermissionLevels);
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
};
|
||||
|
||||
use crate::util::impl_deref_wrapped;
|
||||
use crate::util::{from_repeated_enum, from_repeated_message};
|
||||
use crate::util::{impl_from_repeated, impl_from_repeated_copy};
|
||||
|
||||
use protocol::metadata::Restriction as RestrictionMessage;
|
||||
|
||||
|
@ -68,8 +68,8 @@ impl From<&RestrictionMessage> for Restriction {
|
|||
}
|
||||
}
|
||||
|
||||
from_repeated_message!(RestrictionMessage, Restrictions);
|
||||
from_repeated_enum!(RestrictionCatalogue, RestrictionCatalogues);
|
||||
impl_from_repeated!(RestrictionMessage, Restrictions);
|
||||
impl_from_repeated_copy!(RestrictionCatalogue, RestrictionCatalogues);
|
||||
|
||||
struct StrChunks<'s>(&'s str, usize);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
|||
|
||||
use crate::{
|
||||
restriction::Restrictions,
|
||||
util::{impl_deref_wrapped, try_from_repeated_message},
|
||||
util::{impl_deref_wrapped, impl_try_from_repeated},
|
||||
};
|
||||
|
||||
use librespot_core::date::Date;
|
||||
|
@ -37,4 +37,4 @@ impl TryFrom<&SalePeriodMessage> for SalePeriod {
|
|||
}
|
||||
}
|
||||
|
||||
try_from_repeated_message!(SalePeriodMessage, SalePeriods);
|
||||
impl_try_from_repeated!(SalePeriodMessage, SalePeriods);
|
||||
|
|
|
@ -17,7 +17,7 @@ use crate::{
|
|||
external_id::ExternalIds,
|
||||
restriction::Restrictions,
|
||||
sale_period::SalePeriods,
|
||||
util::{impl_deref_wrapped, try_from_repeated_message},
|
||||
util::{impl_deref_wrapped, impl_try_from_repeated},
|
||||
Album, Metadata, RequestResult,
|
||||
};
|
||||
|
||||
|
@ -141,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) => {
|
||||
impl From<&[$src]> for $dst {
|
||||
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) => {
|
||||
impl From<&[$src]> for $dst {
|
||||
fn from(src: &[$src]) -> Self {
|
||||
let result = src.iter().map(|x| <$src>::from(*x)).collect();
|
||||
let result = src.iter().copied().collect();
|
||||
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) => {
|
||||
impl TryFrom<&[$src]> for $dst {
|
||||
type Error = librespot_core::Error;
|
||||
|
@ -36,7 +36,7 @@ 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) => {
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use crate::util::{from_repeated_message, impl_deref_wrapped};
|
||||
use crate::util::{impl_deref_wrapped, impl_from_repeated};
|
||||
|
||||
use librespot_core::FileId;
|
||||
|
||||
|
@ -15,4 +15,4 @@ pub struct VideoFiles(pub Vec<FileId>);
|
|||
|
||||
impl_deref_wrapped!(VideoFiles, Vec<FileId>);
|
||||
|
||||
from_repeated_message!(VideoFileMessage, VideoFiles);
|
||||
impl_from_repeated!(VideoFileMessage, VideoFiles);
|
||||
|
|
Loading…
Reference in a new issue