Commit 5972ce58 authored by Leonardo Schwarz's avatar Leonardo Schwarz

Update to Rust 2018 edition.

parent 21035970
......@@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["Leo Schwarz <mail@leoschwarz.com>"]
license = "Apache-2.0"
repository = "https://github.com/leoschwarz/musicbrainz_rust"
edition = "2018"
[features]
default = []
......
......@@ -37,7 +37,7 @@ mod tests {
#[test]
fn error() {
let context = ::util::musicbrainz_context();
let context = crate::util::musicbrainz_context();
let reader = Reader::from_str(XML_ERR, Some(&context)).unwrap();
let res = check_response_error(&reader);
......@@ -50,7 +50,7 @@ mod tests {
#[test]
fn ok() {
let context = ::util::musicbrainz_context();
let context = crate::util::musicbrainz_context();
let reader = Reader::from_str(XML_OK, Some(&context)).unwrap();
// should not raise error
......
//! Contains the types and functions to communicate with the MusicBrainz API.
use errors::{ClientError, ClientErrorKind};
use entities::{Mbid, Resource};
use crate::errors::{ClientError, ClientErrorKind};
use crate::entities::{Mbid, Resource};
use reqwest_mock::Client as MockClient;
use reqwest_mock::GenericClient as HttpClient;
......@@ -12,7 +12,7 @@ use xpath_reader::reader::{FromXml, Reader};
use std::time::{Duration, Instant};
use std::thread::sleep;
use search::{AreaSearchBuilder, ArtistSearchBuilder, ReleaseGroupSearchBuilder, SearchBuilder};
use crate::search::{AreaSearchBuilder, ArtistSearchBuilder, ReleaseGroupSearchBuilder, SearchBuilder};
mod error;
pub(crate) use self::error::check_response_error;
......@@ -137,7 +137,7 @@ impl Client {
let response_body = self.get_body(url.parse()?)?;
// Parse the response.
let context = ::util::musicbrainz_context();
let context = crate::util::musicbrainz_context();
let reader = Reader::from_str(&response_body[..], Some(&context))?;
check_response_error(&reader)?;
Ok(Res::from_xml(&reader)?)
......@@ -205,7 +205,7 @@ mod tests {
let mut client = get_client("release_group_01");
let results = client
.search_release_group()
.add(::search::fields::release_group::ReleaseGroupName(
.add(crate::search::fields::release_group::ReleaseGroupName(
"霊魂消滅".to_owned(),
))
.search()
......
use xpath_reader::{FromXml, Error, Reader};
use entities::{Mbid, Resource};
use crate::entities::{Mbid, Resource};
enum_mb_xml! {
/// Specifies what a specific `Area` instance actually is.
......@@ -84,7 +84,7 @@ mod tests {
#[test]
fn area_read_xml1() {
let mbid = Mbid::from_str("a1411661-be21-4290-8dc1-50f3d8e3ea67").unwrap();
let area: Area = ::util::test_utils::fetch_entity(&mbid).unwrap();
let area: Area = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(area.mbid, mbid);
assert_eq!(area.name, "Honolulu".to_string());
......@@ -96,7 +96,7 @@ mod tests {
#[test]
fn area_read_xml2() {
let mbid = Mbid::from_str("2db42837-c832-3c27-b4a3-08198f75693c").unwrap();
let area: Area = ::util::test_utils::fetch_entity(&mbid).unwrap();
let area: Area = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(area.mbid, mbid);
assert_eq!(area.name, "Japan".to_string());
......
use xpath_reader::{FromXml, FromXmlOptional, Error, Reader};
use entities::{Mbid, Resource};
use entities::date::PartialDate;
use entities::refs::AreaRef;
use crate::entities::{Mbid, Resource};
use crate::entities::date::PartialDate;
use crate::entities::refs::AreaRef;
enum_mb_xml_optional! {
/// Specification of the gender of an artist.
......@@ -122,7 +122,7 @@ mod tests {
#[test]
fn artist_read_xml1() {
let mbid = Mbid::from_str("90e7c2f9-273b-4d6c-a662-ab2d73ea4b8e").unwrap();
let artist: Artist = ::util::test_utils::fetch_entity(&mbid).unwrap();
let artist: Artist = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(artist.mbid, mbid);
assert_eq!(artist.name, "NECRONOMIDOL".to_string());
......@@ -153,7 +153,7 @@ mod tests {
#[test]
fn artist_read_xml2() {
let mbid = Mbid::from_str("650e7db6-b795-4eb5-a702-5ea2fc46c848").unwrap();
let artist: Artist = ::util::test_utils::fetch_entity(&mbid).unwrap();
let artist: Artist = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(artist.mbid, mbid);
assert_eq!(artist.name, "Lady Gaga".to_string());
......
use xpath_reader::{FromXml, FromXmlOptional, Error, Reader};
use entities::{Mbid, Resource};
use entities::date::PartialDate;
use crate::entities::{Mbid, Resource};
use crate::entities::date::PartialDate;
enum_mb_xml_optional! {
pub enum EventType {
......@@ -81,7 +81,7 @@ mod tests {
#[test]
fn read_1() {
let mbid = Mbid::from_str("6e2ab7d5-f340-4c41-99a3-c901733402b4").unwrap();
let event: Event = ::util::test_utils::fetch_entity(&mbid).unwrap();
let event: Event = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(event.mbid, mbid);
assert_eq!(event.name, "25. Wave-Gotik-Treffen".to_string());
......@@ -97,7 +97,7 @@ mod tests {
#[test]
fn read_2() {
let mbid = Mbid::from_str("9754f4dd-6fad-49b7-8f30-940c9af6b776").unwrap();
let event: Event = ::util::test_utils::fetch_entity(&mbid).unwrap();
let event: Event = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(event.event_type, Some(EventType::Concert));
assert_eq!(event.setlist.unwrap().len(), 225);
......
use xpath_reader::{FromXml, FromXmlOptional, Error, Reader};
use entities::{Mbid, Resource};
use entities::date::PartialDate;
use crate::entities::{Mbid, Resource};
use crate::entities::date::PartialDate;
/// A label entity in the MusicBrainz database.
/// There is quite some controversy in the music industry what a 'label'
......@@ -120,7 +120,7 @@ mod tests {
#[test]
fn label_read_xml1() {
let mbid = Mbid::from_str("c029628b-6633-439e-bcee-ed02e8a338f7").unwrap();
let label: Label = ::util::test_utils::fetch_entity(&mbid).unwrap();
let label: Label = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(label.mbid, mbid);
assert_eq!(label.name, "EMI".to_string());
......@@ -153,7 +153,7 @@ mod tests {
#[test]
fn read_aliases() {
let mbid = Mbid::from_str("168f48c8-057e-4974-9600-aa9956d21e1a").unwrap();
let label: Label = ::util::test_utils::fetch_entity(&mbid).unwrap();
let label: Label = crate::util::test_utils::fetch_entity(&mbid).unwrap();
let mut expected = vec![
"Avex Trax Japan".to_string(),
......
use errors::ParseError;
use crate::errors::ParseError;
use isolang::Language as IsoLang;
use std::fmt;
use xpath_reader::{FromXml, FromXmlOptional, Error, Reader};
......
use entities::{Mbid, PartialDate, Resource};
use entities::refs::AreaRef;
use crate::entities::{Mbid, PartialDate, Resource};
use crate::entities::refs::AreaRef;
use xpath_reader::{FromXml, FromXmlOptional, Error, Reader};
enum_mb_xml_optional! {
......@@ -111,7 +111,7 @@ mod tests {
#[test]
fn place_read_1() {
let mbid = Mbid::from_str("d1ab65f8-d082-492a-bd70-ce375548dabf").unwrap();
let p: Place = ::util::test_utils::fetch_entity(&mbid).unwrap();
let p: Place = crate::util::test_utils::fetch_entity(&mbid).unwrap();
// Check parsed values.
assert_eq!(p.mbid, mbid);
......
use std::time::Duration;
use xpath_reader::{FromXml, Error, Reader};
use entities::{Mbid, Resource};
use entities::refs::ArtistRef;
use crate::entities::{Mbid, Resource};
use crate::entities::refs::ArtistRef;
/// Represents a unique audio that has been used to produce at least one
/// released track through
......@@ -38,7 +38,7 @@ impl FromXml for Recording {
mbid: reader.read(".//mb:recording/@id")?,
title: reader.read(".//mb:recording/mb:title/text()")?,
artists: reader.read(".//mb:recording/mb:artist-credit/mb:name-credit")?,
duration: ::entities::helper::read_mb_duration(
duration: crate::entities::helper::read_mb_duration(
reader,
".//mb:recording/mb:length/text()",
)?,
......@@ -62,7 +62,7 @@ mod tests {
#[test]
fn read_xml1() {
let mbid = Mbid::from_str("fbe3d0b9-3990-4a76-bddb-12f4a0447a2c").unwrap();
let recording: Recording = ::util::test_utils::fetch_entity(&mbid).unwrap();
let recording: Recording = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(recording.mbid, mbid);
assert_eq!(
......
......@@ -6,12 +6,12 @@
use std::time::Duration;
use xpath_reader::{FromXml, FromXmlOptional, Error, Reader};
use entities::Mbid;
use entities::date::PartialDate;
use entities::release::ReleaseStatus;
use crate::entities::Mbid;
use crate::entities::date::PartialDate;
use crate::entities::release::ReleaseStatus;
use client::Client;
use errors::ClientError;
use crate::client::Client;
use crate::errors::ClientError;
pub trait FetchFull {
type Full;
......@@ -91,7 +91,7 @@ impl FromXml for RecordingRef {
Ok(RecordingRef {
mbid: reader.read(".//@id")?,
title: reader.read(".//mb:title/text()")?,
length: ::entities::helper::read_mb_duration(reader, ".//mb:length/text()")?,
length: crate::entities::helper::read_mb_duration(reader, ".//mb:length/text()")?,
})
}
}
......@@ -136,9 +136,9 @@ macro_rules! ref_fetch_full
}
ref_fetch_full!(
AreaRef, ::entities::Area;
ArtistRef, ::entities::Artist;
LabelRef, ::entities::Label;
RecordingRef, ::entities::Recording;
ReleaseRef, ::entities::Release
AreaRef, crate::entities::Area;
ArtistRef, crate::entities::Artist;
LabelRef, crate::entities::Label;
RecordingRef, crate::entities::Recording;
ReleaseRef, crate::entities::Release
);
use std::time::Duration;
use xpath_reader::{FromXml, FromXmlOptional, Error, Reader};
use entities::{Language, Mbid, Resource};
use entities::date::PartialDate;
use entities::refs::{ArtistRef, LabelRef, RecordingRef};
use crate::entities::{Language, Mbid, Resource};
use crate::entities::date::PartialDate;
use crate::entities::refs::{ArtistRef, LabelRef, RecordingRef};
/// Describes a single track, `Releases` consist of multiple `ReleaseTrack`s.
#[derive(Clone, Debug, Eq, PartialEq)]
......@@ -40,7 +40,7 @@ impl FromXml for ReleaseTrack {
position: reader.read(".//mb:position/text()")?,
number: reader.read(".//mb:number/text()")?,
title: reader.read(".//mb:title/text()")?,
length: ::entities::helper::read_mb_duration(reader, ".//mb:length/text()")?,
length: crate::entities::helper::read_mb_duration(reader, ".//mb:length/text()")?,
recording: reader.read(".//mb:recording")?,
})
}
......@@ -220,7 +220,7 @@ mod tests {
#[test]
fn release_read_xml1() {
let mbid = Mbid::from_str("ed118c5f-d940-4b52-a37b-b1a205374abe").unwrap();
let release: Release = ::util::test_utils::fetch_entity(&mbid).unwrap();
let release: Release = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(release.mbid, mbid);
assert_eq!(release.title, "Creep".to_string());
......@@ -260,7 +260,7 @@ mod tests {
#[test]
fn disambiguation() {
let mbid = Mbid::from_str("9642c552-a5b3-4b7e-9168-aeb2a1a06f27").unwrap();
let release: Release = ::util::test_utils::fetch_entity(&mbid).unwrap();
let release: Release = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(release.disambiguation, Some("通常盤".to_string()));
}
......@@ -268,7 +268,7 @@ mod tests {
#[test]
fn release_read_xml2() {
let mbid = Mbid::from_str("785d7c67-a920-4cee-a871-8cd9896eb8aa").unwrap();
let release: Release = ::util::test_utils::fetch_entity(&mbid).unwrap();
let release: Release = crate::util::test_utils::fetch_entity(&mbid).unwrap();
// We check for the things we didn't check in the previous test.
assert_eq!(release.packaging, Some("Jewel Case".to_string()));
......@@ -328,7 +328,7 @@ mod tests {
#[test]
fn read_tracks() {
let mbid = Mbid::from_str("d1881a4c-0188-4f0f-a2e7-4e7849aec109").unwrap();
let release: Release = ::util::test_utils::fetch_entity(&mbid).unwrap();
let release: Release = crate::util::test_utils::fetch_entity(&mbid).unwrap();
let mediums = release.mediums;
assert_eq!(mediums.len(), 1);
......@@ -385,7 +385,7 @@ mod tests {
#[test]
fn tracks_without_length() {
let mbid = Mbid::from_str("02173013-59ed-4229-b0a5-e5aa486ed5d7").unwrap();
let release: Release = ::util::test_utils::fetch_entity(&mbid).unwrap();
let release: Release = crate::util::test_utils::fetch_entity(&mbid).unwrap();
let ref medium = release.mediums[0];
assert_eq!(medium.tracks[0].length, None);
......@@ -397,7 +397,7 @@ mod tests {
#[test]
fn multi_cd() {
let mbid = Mbid::from_str("ce22b20d-3a45-4e47-abaa-b7c8d10281fa").unwrap();
let release: Release = ::util::test_utils::fetch_entity(&mbid).unwrap();
let release: Release = crate::util::test_utils::fetch_entity(&mbid).unwrap();
let mediums = release.mediums;
......@@ -423,7 +423,7 @@ mod tests {
#[test]
fn catalog_number_but_no_label_ref() {
let mbid = Mbid::from_str("61f8b05f-a3b5-49f4-a3a6-8f0d564c1664").unwrap();
let release: Release = ::util::test_utils::fetch_entity(&mbid).unwrap();
let release: Release = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(
release.labels,
......
use xpath_reader::{FromXml, FromXmlOptional, Error, Reader};
use entities::{Mbid, Resource};
use entities::refs::{ArtistRef, ReleaseRef};
use crate::entities::{Mbid, Resource};
use crate::entities::refs::{ArtistRef, ReleaseRef};
enum_mb_xml_optional! {
/// The primary type of a release group.
......@@ -102,12 +102,12 @@ impl FromXml for ReleaseGroup {
mod tests {
use super::*;
use std::str::FromStr;
use entities::*;
use crate::entities::*;
#[test]
fn read_1() {
let mbid = Mbid::from_str("76a4e2c2-bf7a-445e-8081-5a1e291f3b16").unwrap();
let rg: ReleaseGroup = ::util::test_utils::fetch_entity(&mbid).unwrap();
let rg: ReleaseGroup = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(rg.mbid, mbid);
assert_eq!(rg.title, "Mixtape".to_string());
......
use entities::{Mbid, PartialDate, Resource};
use entities::refs::AreaRef;
use crate::entities::{Mbid, PartialDate, Resource};
use crate::entities::refs::AreaRef;
use xpath_reader::{FromXml, Error, Reader};
enum_mb_xml! {
......@@ -60,7 +60,7 @@ mod tests {
#[test]
fn read_series_1() {
let mbid = Mbid::from_str("d977f7fd-96c9-4e3e-83b5-eb484a9e6582").unwrap();
let series: Series = ::util::test_utils::fetch_entity(&mbid).unwrap();
let series: Series = crate::util::test_utils::fetch_entity(&mbid).unwrap();
assert_eq!(series.mbid, mbid);
assert_eq!(series.series_type, SeriesType::Catalogue);
......
......@@ -13,10 +13,10 @@
//! full entity from a search entity, using the `fetch_full()` method on the
//! search entity.
use entities as full_entities;
use entities::Resource;
use errors::ClientError;
use client::Client;
use crate::entities as full_entities;
use crate::entities::Resource;
use crate::errors::ClientError;
use crate::client::Client;
use reqwest_mock::Url;
use url::percent_encoding::{DEFAULT_ENCODE_SET, utf8_percent_encode};
......@@ -108,11 +108,11 @@ macro_rules! define_search_builder {
/// Parse the search result.
fn parse_xml(xml: &str) -> SearchResult<$entity> {
let mut context = ::util::musicbrainz_context();
let mut context = crate::util::musicbrainz_context();
context.set_namespace("ext", "http://musicbrainz.org/ns/ext#-2.0");
let reader = Reader::from_str(xml, Some(&context))?;
::client::check_response_error(&reader)?;
crate::client::check_response_error(&reader)?;
Ok(reader.read("//mb:metadata")?)
}
}
......
......@@ -8,9 +8,9 @@ pub fn musicbrainz_context<'d>() -> Context<'d> {
#[cfg(test)]
pub mod test_utils {
use client::{Client, ClientConfig, ClientWaits};
use entities::{Mbid, Resource};
use errors::ClientError;
use crate::client::{Client, ClientConfig, ClientWaits};
use crate::entities::{Mbid, Resource};
use crate::errors::ClientError;
use reqwest_mock::GenericClient as HttpClient;
use xpath_reader::reader::FromXml;
......
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