spotify_rs/
endpoint.rs

1use serde::Serialize;
2
3pub mod album;
4pub mod artist;
5pub mod audiobook;
6pub mod category;
7pub mod genres;
8pub mod markets;
9pub mod player;
10pub mod playlist;
11pub mod search;
12pub mod show;
13pub mod track;
14pub mod user;
15
16// Authenticated client type to make it more convenient to use in the endpoints.
17type Client<F> = crate::client::Client<crate::auth::Token, F>;
18
19#[doc = include_str!("docs/internal_implementation_details.md")]
20pub trait Endpoint: Serialize {
21    // This method isn't necessary, thus it's not implemented for all endpoints
22    // It's used for pagination, for keeping track of the current endpoint
23    // a `Page` refers to.
24    //
25    // However, in the future it might be implemented for all endpoints,
26    // for consistency's sake.
27    fn endpoint_url(&self) -> &'static str {
28        "TODO (default URL)"
29    }
30}
31
32impl<T: Endpoint> EndpointPrivate for T {}
33
34// Trait to add endpoint methods that make writing the endpoints
35// more convenient.
36pub(crate) trait EndpointPrivate: Serialize + Endpoint {
37    // Convenience method used to convert a type (an endpoint in this case)
38    // to a Body::Json.
39    fn json(self) -> crate::client::Body<Self>
40    where
41        Self: Sized,
42    {
43        crate::client::Body::Json(self)
44    }
45}