1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-03 01:39:28 +02:00

Pass by reference

This commit is contained in:
Roderick van Domburg 2022-08-03 22:26:52 +02:00
parent 70eb3f9d72
commit 80f0d3c59b
No known key found for this signature in database
GPG key ID: 87F5FDE8A56219F4
11 changed files with 55 additions and 58 deletions

View file

@ -76,11 +76,11 @@ impl Album {
impl Metadata for Album {
type Message = protocol::metadata::Album;
async fn request(session: &Session, album_id: SpotifyId) -> RequestResult {
async fn request(session: &Session, album_id: &SpotifyId) -> RequestResult {
session.spclient().get_album_metadata(album_id).await
}
fn parse(msg: &Self::Message, _: SpotifyId) -> Result<Self, Error> {
fn parse(msg: &Self::Message, _: &SpotifyId) -> Result<Self, Error> {
Self::try_from(msg)
}
}

View file

@ -171,11 +171,11 @@ impl Artist {
impl Metadata for Artist {
type Message = protocol::metadata::Artist;
async fn request(session: &Session, artist_id: SpotifyId) -> RequestResult {
async fn request(session: &Session, artist_id: &SpotifyId) -> RequestResult {
session.spclient().get_artist_metadata(artist_id).await
}
fn parse(msg: &Self::Message, _: SpotifyId) -> Result<Self, Error> {
fn parse(msg: &Self::Message, _: &SpotifyId) -> Result<Self, Error> {
Self::try_from(msg)
}
}

View file

@ -60,7 +60,7 @@ impl_deref_wrapped!(Episodes, Vec<SpotifyId>);
#[async_trait]
impl InnerAudioItem for Episode {
async fn get_audio_item(session: &Session, id: SpotifyId) -> AudioItemResult {
let episode = Self::get(session, id).await?;
let episode = Self::get(session, &id).await?;
let availability = Self::available_for_user(
&session.user_data(),
&episode.availability,
@ -84,11 +84,11 @@ impl InnerAudioItem for Episode {
impl Metadata for Episode {
type Message = protocol::metadata::Episode;
async fn request(session: &Session, episode_id: SpotifyId) -> RequestResult {
async fn request(session: &Session, episode_id: &SpotifyId) -> RequestResult {
session.spclient().get_episode_metadata(episode_id).await
}
fn parse(msg: &Self::Message, _: SpotifyId) -> Result<Self, Error> {
fn parse(msg: &Self::Message, _: &SpotifyId) -> Result<Self, Error> {
Self::try_from(msg)
}
}

View file

@ -42,15 +42,15 @@ pub trait Metadata: Send + Sized + 'static {
type Message: protobuf::Message;
// Request a protobuf
async fn request(session: &Session, id: SpotifyId) -> RequestResult;
async fn request(session: &Session, id: &SpotifyId) -> RequestResult;
// Request a metadata struct
async fn get(session: &Session, id: SpotifyId) -> Result<Self, Error> {
async fn get(session: &Session, id: &SpotifyId) -> Result<Self, Error> {
let response = Self::request(session, id).await?;
let msg = Self::Message::parse_from_bytes(&response)?;
trace!("Received metadata: {:#?}", msg);
Self::parse(&msg, id)
}
fn parse(msg: &Self::Message, _: SpotifyId) -> Result<Self, Error>;
fn parse(msg: &Self::Message, _: &SpotifyId) -> Result<Self, Error>;
}

View file

@ -27,12 +27,12 @@ pub struct PlaylistAnnotation {
impl Metadata for PlaylistAnnotation {
type Message = protocol::playlist_annotate3::PlaylistAnnotation;
async fn request(session: &Session, playlist_id: SpotifyId) -> RequestResult {
async fn request(session: &Session, playlist_id: &SpotifyId) -> RequestResult {
let current_user = session.username();
Self::request_for_user(session, &current_user, playlist_id).await
}
fn parse(msg: &Self::Message, _: SpotifyId) -> Result<Self, Error> {
fn parse(msg: &Self::Message, _: &SpotifyId) -> Result<Self, Error> {
Ok(Self {
description: msg.get_description().to_owned(),
picture: msg.get_picture().to_owned(), // TODO: is this a URL or Spotify URI?
@ -47,7 +47,7 @@ impl PlaylistAnnotation {
async fn request_for_user(
session: &Session,
username: &str,
playlist_id: SpotifyId,
playlist_id: &SpotifyId,
) -> RequestResult {
let uri = format!(
"hm://playlist-annotate/v1/annotation/user/{}/playlist/{}",
@ -61,7 +61,7 @@ impl PlaylistAnnotation {
async fn get_for_user(
session: &Session,
username: &str,
playlist_id: SpotifyId,
playlist_id: &SpotifyId,
) -> Result<Self, Error> {
let response = Self::request_for_user(session, username, playlist_id).await?;
let msg = <Self as Metadata>::Message::parse_from_bytes(&response)?;

View file

@ -97,14 +97,14 @@ impl Playlist {
impl Metadata for Playlist {
type Message = protocol::playlist4_external::SelectedListContent;
async fn request(session: &Session, playlist_id: SpotifyId) -> RequestResult {
async fn request(session: &Session, playlist_id: &SpotifyId) -> RequestResult {
session.spclient().get_playlist(playlist_id).await
}
fn parse(msg: &Self::Message, id: SpotifyId) -> Result<Self, Error> {
fn parse(msg: &Self::Message, id: &SpotifyId) -> Result<Self, Error> {
// the playlist proto doesn't contain the id so we decorate it
let playlist = SelectedListContent::try_from(msg)?;
let id = NamedSpotifyId::from_spotify_id(id, playlist.owner_username);
let id = NamedSpotifyId::from_spotify_id(*id, &playlist.owner_username);
Ok(Self {
id,

View file

@ -39,11 +39,11 @@ pub struct Show {
impl Metadata for Show {
type Message = protocol::metadata::Show;
async fn request(session: &Session, show_id: SpotifyId) -> RequestResult {
async fn request(session: &Session, show_id: &SpotifyId) -> RequestResult {
session.spclient().get_show_metadata(show_id).await
}
fn parse(msg: &Self::Message, _: SpotifyId) -> Result<Self, Error> {
fn parse(msg: &Self::Message, _: &SpotifyId) -> Result<Self, Error> {
Self::try_from(msg)
}
}

View file

@ -61,7 +61,7 @@ impl_deref_wrapped!(Tracks, Vec<SpotifyId>);
#[async_trait]
impl InnerAudioItem for Track {
async fn get_audio_item(session: &Session, id: SpotifyId) -> AudioItemResult {
let track = Self::get(session, id).await?;
let track = Self::get(session, &id).await?;
let alternatives = {
if track.alternatives.is_empty() {
None
@ -98,11 +98,11 @@ impl InnerAudioItem for Track {
impl Metadata for Track {
type Message = protocol::metadata::Track;
async fn request(session: &Session, track_id: SpotifyId) -> RequestResult {
async fn request(session: &Session, track_id: &SpotifyId) -> RequestResult {
session.spclient().get_track_metadata(track_id).await
}
fn parse(msg: &Self::Message, _: SpotifyId) -> Result<Self, Error> {
fn parse(msg: &Self::Message, _: &SpotifyId) -> Result<Self, Error> {
Self::try_from(msg)
}
}