Commit 2c2095bb authored by Leonardo Schwarz's avatar Leonardo Schwarz

Use associated consts. Yay

parent 6021e215
......@@ -78,15 +78,8 @@ impl FromXml for Area {
}
impl Resource for Area {
fn get_name() -> &'static str
{
"area"
}
fn get_incs() -> &'static str
{
""
}
const NAME: &'static str = "area";
const INCL: &'static str = "";
}
#[cfg(test)]
......
......@@ -115,15 +115,8 @@ impl FromXml for Artist {
}
impl Resource for Artist {
fn get_name() -> &'static str
{
"artist"
}
fn get_incs() -> &'static str
{
"aliases"
}
const NAME: &'static str = "artist";
const INCL: &'static str = "aliases";
}
#[cfg(test)]
......
......@@ -54,15 +54,8 @@ pub struct Event {
}
impl Resource for Event {
fn get_name() -> &'static str
{
"event"
}
fn get_incs() -> &'static str
{
"aliases+annotation"
}
const NAME: &'static str = "event";
const INCL: &'static str = "aliases+annotation";
}
impl FromXmlContained for Event {}
......
......@@ -58,15 +58,8 @@ pub struct Label {
}
impl Resource for Label {
fn get_name() -> &'static str
{
"label"
}
fn get_incs() -> &'static str
{
"aliases"
}
const NAME: &'static str = "label";
const INCL: &'static str = "aliases";
}
impl FromXmlContained for Label {}
......
......@@ -39,23 +39,37 @@ pub use self::release_group::{ReleaseGroup, ReleaseGroupPrimaryType, ReleaseGrou
// TODO it's pretty useless as of now.
// pub use self::series::Series;
use std::marker::PhantomData;
mod mbid;
pub use self::mbid::Mbid;
// TODO: Convert get_name and get_incs into associated consts once these land
// in stable rust.
/// Represents an instance of an entity from the database.
///
/// Along with the data of the entity this can also optionally hold
/// relationship data from the database.
pub struct Entity<E> {
/// The actual data of the entity.
pub data: E,
/// The relationship data of the entity.
pub rels: Vec<Relationship<E>>,
}
pub struct Relationship<E> {
_e: PhantomData<E>,
}
/// A Resource is any entity which can be directly retrieved from MusicBrainz.
///
/// We define this trait for the sake of using the `Client` type more
/// efficiently, users of the `musicbrainz` crate shouldn't need to use this
/// type directly.
pub trait Resource {
/// Returns the name of the Resource, e. g. `"artist"`.
fn get_name() -> &'static str;
/// Returns the query string value of the things to include in a request
/// fetching an instance of the full entity.
fn get_incs() -> &'static str;
/// Name of the resource for inclusion in api paths, e.g. `artist`.
const NAME: &'static str;
/// Query string component of includes to be requested by default.
const INCL: &'static str;
/// Returns the url where one can get a resource in the valid format for
/// parsing from.
......@@ -63,9 +77,9 @@ pub trait Resource {
{
format!(
"https://musicbrainz.org/ws/2/{}/{}?inc={}",
Self::get_name(),
Self::NAME,
mbid,
Self::get_incs()
Self::INCL
)
}
}
......
......@@ -103,15 +103,8 @@ impl FromXml for Place {
}
impl Resource for Place {
fn get_name() -> &'static str
{
"place"
}
fn get_incs() -> &'static str
{
"annotation+aliases"
}
const NAME: &'static str = "place";
const INCL: &'static str = "annotation+aliases";
}
#[cfg(test)]
......
......@@ -55,15 +55,8 @@ impl FromXml for Recording {
}
impl Resource for Recording {
fn get_name() -> &'static str
{
"recording"
}
fn get_incs() -> &'static str
{
"artists+annotation+isrcs"
}
const NAME: &'static str = "recording";
const INCL: &'static str = "artists+annotation+isrcs";
}
#[cfg(test)]
......
......@@ -226,15 +226,8 @@ impl FromXml for Release {
}
impl Resource for Release {
fn get_name() -> &'static str
{
"release"
}
fn get_incs() -> &'static str
{
"aliases+annotation+artists+labels+recordings"
}
const NAME: &'static str = "release";
const INCL: &'static str = "aliases+annotation+artists+labels+recordings";
}
#[cfg(test)]
......
......@@ -84,15 +84,8 @@ pub struct ReleaseGroup {
}
impl Resource for ReleaseGroup {
fn get_name() -> &'static str
{
"release-group"
}
fn get_incs() -> &'static str
{
"annotation+artists+releases"
}
const NAME: &'static str = "release-group";
const INCL: &'static str = "annotation+artists+releases";
}
impl FromXmlContained for ReleaseGroup {}
......
......@@ -54,15 +54,8 @@ impl FromXml for Series {
}
impl Resource for Series {
fn get_name() -> &'static str
{
"series"
}
fn get_incs() -> &'static str
{
"annotation+aliases+work-rels"
}
const NAME: &'static str = "series";
const INCL: &'static str = "annotation+aliases+work-rels";
}
#[cfg(test)]
......
......@@ -99,7 +99,7 @@ macro_rules! define_search_builder {
// TODO: In the future support OR queries too.
let query = query_parts.join("%20AND%20");
type FE = $full_entity;
let base_url = format!("https://musicbrainz.org/ws/2/{}/", FE::get_name());
let base_url = format!("https://musicbrainz.org/ws/2/{}/", FE::NAME);
Ok(Url::parse(format!("{}?query={}", base_url, query).as_ref())?)
}
......
......@@ -25,7 +25,7 @@ pub mod test_utils {
},
HttpClient::replay_file(format!(
"replay/test_entities/{}/{}.json",
E::get_name(),
E::NAME,
mbid
)),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment