Skip to content

Commit 8c67d7b

Browse files
committed
chore: remove async-trait
1 parent f3a3463 commit 8c67d7b

11 files changed

Lines changed: 23 additions & 21 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

metadata/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ rustls-tls-webpki-roots = ["librespot-core/rustls-tls-webpki-roots"]
2121
librespot-core = { version = "0.8.0", path = "../core", default-features = false }
2222
librespot-protocol = { version = "0.8.0", path = "../protocol", default-features = false }
2323

24-
async-trait = "0.1"
2524
bytes = "1"
2625
log = "0.4"
2726
protobuf = "3.7"

metadata/src/album.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ impl Album {
7070
}
7171
}
7272

73-
#[async_trait]
7473
impl Metadata for Album {
7574
type Message = protocol::metadata::Album;
7675

metadata/src/artist.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ impl Artist {
167167
}
168168
}
169169

170-
#[async_trait]
171170
impl Metadata for Artist {
172171
type Message = protocol::metadata::Artist;
173172

metadata/src/episode.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ pub struct Episodes(pub Vec<SpotifyUri>);
5353

5454
impl_deref_wrapped!(Episodes, Vec<SpotifyUri>);
5555

56-
#[async_trait]
5756
impl Metadata for Episode {
5857
type Message = protocol::metadata::Episode;
5958

metadata/src/lib.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#[macro_use]
22
extern crate log;
33

4-
#[macro_use]
5-
extern crate async_trait;
6-
74
use protobuf::Message;
5+
use std::future::Future;
86

97
use librespot_core::{Error, Session, SpotifyUri};
108

@@ -39,20 +37,34 @@ pub use playlist::Playlist;
3937
pub use show::Show;
4038
pub use track::Track;
4139

42-
#[async_trait]
4340
pub trait Metadata: Send + Sized + 'static {
44-
type Message: protobuf::Message + std::fmt::Debug;
41+
type Message: Message + std::fmt::Debug;
4542

4643
// Request a protobuf
47-
async fn request(session: &Session, id: &SpotifyUri) -> RequestResult;
44+
fn request(
45+
session: &Session,
46+
id: &SpotifyUri,
47+
) -> impl Future<Output = RequestResult> + Send + Sized;
4848

4949
// Request a metadata struct
50-
async fn get(session: &Session, id: &SpotifyUri) -> Result<Self, Error> {
51-
let response = Self::request(session, id).await?;
52-
let msg = Self::Message::parse_from_bytes(&response)?;
53-
trace!("Received metadata: {msg:#?}");
54-
Self::parse(&msg, id)
50+
fn get(
51+
session: &Session,
52+
id: &SpotifyUri,
53+
) -> impl Future<Output = Result<Self, Error>> + Send + Sized {
54+
map_request_to_message(Self::request(session, id), id)
5555
}
5656

5757
fn parse(msg: &Self::Message, _: &SpotifyUri) -> Result<Self, Error>;
5858
}
59+
60+
async fn map_request_to_message<M, P, F>(response: F, uri: &SpotifyUri) -> Result<M, Error>
61+
where
62+
P: Message + std::fmt::Debug,
63+
M: Metadata<Message = P>,
64+
F: Future<Output = RequestResult> + Send + Sized,
65+
{
66+
let response = response.await?;
67+
let msg = P::parse_from_bytes(&response)?;
68+
trace!("Received metadata: {msg:#?}");
69+
M::parse(&msg, uri)
70+
}

metadata/src/playlist/annotation.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub struct PlaylistAnnotation {
2121
pub abuse_report_state: AbuseReportState,
2222
}
2323

24-
#[async_trait]
2524
impl Metadata for PlaylistAnnotation {
2625
type Message = protocol::playlist_annotate3::PlaylistAnnotation;
2726

metadata/src/playlist/list.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ impl Playlist {
8484
}
8585
}
8686

87-
#[async_trait]
8887
impl Metadata for Playlist {
8988
type Message = protocol::playlist4_external::SelectedListContent;
9089

metadata/src/request.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use librespot_core::{Error, Session};
66

77
pub type RequestResult = Result<bytes::Bytes, Error>;
88

9-
#[async_trait]
109
pub trait MercuryRequest {
1110
async fn request(session: &Session, uri: &str) -> RequestResult {
1211
let mut metrics_uri = uri.to_owned();

metadata/src/show.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ pub struct Show {
3232
pub is_audiobook: bool,
3333
}
3434

35-
#[async_trait]
3635
impl Metadata for Show {
3736
type Message = protocol::metadata::Show;
3837

0 commit comments

Comments
 (0)