1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-04 18:29:45 +02:00

rustfmt: core

This commit is contained in:
awiouy 2018-02-11 12:37:08 +01:00
parent 0d92ac74d1
commit c9ba73c9ef
21 changed files with 290 additions and 249 deletions

View file

@ -1,20 +1,20 @@
const AP_FALLBACK : &'static str = "ap.spotify.com:80";
const APRESOLVE_ENDPOINT : &'static str = "http://apresolve.spotify.com/";
const AP_FALLBACK: &'static str = "ap.spotify.com:80";
const APRESOLVE_ENDPOINT: &'static str = "http://apresolve.spotify.com/";
use std::str::FromStr;
use futures::{Future, Stream};
use hyper::{self, Uri, Client};
use hyper::{self, Client, Uri};
use serde_json;
use std::str::FromStr;
use tokio_core::reactor::Handle;
error_chain! { }
error_chain!{}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct APResolveData {
ap_list: Vec<String>
ap_list: Vec<String>,
}
fn apresolve(handle: &Handle) -> Box<Future<Item=String, Error=Error>> {
fn apresolve(handle: &Handle) -> Box<Future<Item = String, Error = Error>> {
let url = Uri::from_str(APRESOLVE_ENDPOINT).expect("invalid AP resolve URL");
let client = Client::new(handle);
@ -27,14 +27,10 @@ fn apresolve(handle: &Handle) -> Box<Future<Item=String, Error=Error>> {
})
});
let body = body.then(|result| result.chain_err(|| "HTTP error"));
let body = body.and_then(|body| {
String::from_utf8(body).chain_err(|| "invalid UTF8 in response")
});
let body = body.and_then(|body| String::from_utf8(body).chain_err(|| "invalid UTF8 in response"));
let data = body.and_then(|body| {
serde_json::from_str::<APResolveData>(&body)
.chain_err(|| "invalid JSON")
});
let data =
body.and_then(|body| serde_json::from_str::<APResolveData>(&body).chain_err(|| "invalid JSON"));
let ap = data.and_then(|data| {
let ap = data.ap_list.first().ok_or("empty AP List")?;
@ -44,9 +40,10 @@ fn apresolve(handle: &Handle) -> Box<Future<Item=String, Error=Error>> {
Box::new(ap)
}
pub(crate) fn apresolve_or_fallback<E>(handle: &Handle)
-> Box<Future<Item=String, Error=E>>
where E: 'static {
pub(crate) fn apresolve_or_fallback<E>(handle: &Handle) -> Box<Future<Item = String, Error = E>>
where
E: 'static,
{
let ap = apresolve(handle).or_else(|e| {
warn!("Failed to resolve Access Point: {}", e.description());
warn!("Using fallback \"{}\"", AP_FALLBACK);