mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Remove usage of deprecated BoxFuture, BoxStream and BoxSink
This commit is contained in:
parent
0bdf9aa080
commit
5237203899
8 changed files with 36 additions and 38 deletions
|
@ -4,7 +4,7 @@ mod handshake;
|
|||
pub use self::codec::APCodec;
|
||||
pub use self::handshake::handshake;
|
||||
|
||||
use futures::{Future, Sink, Stream, BoxFuture};
|
||||
use futures::{Future, Sink, Stream};
|
||||
use std::io;
|
||||
use std::net::ToSocketAddrs;
|
||||
use tokio_core::net::TcpStream;
|
||||
|
@ -17,18 +17,18 @@ use version;
|
|||
|
||||
pub type Transport = Framed<TcpStream, APCodec>;
|
||||
|
||||
pub fn connect<A: ToSocketAddrs>(addr: A, handle: &Handle) -> BoxFuture<Transport, io::Error> {
|
||||
pub fn connect<A: ToSocketAddrs>(addr: A, handle: &Handle) -> Box<Future<Item = Transport, Error = io::Error>> {
|
||||
let addr = addr.to_socket_addrs().unwrap().next().unwrap();
|
||||
let socket = TcpStream::connect(&addr, handle);
|
||||
let connection = socket.and_then(|socket| {
|
||||
handshake(socket)
|
||||
});
|
||||
|
||||
connection.boxed()
|
||||
Box::new(connection)
|
||||
}
|
||||
|
||||
pub fn authenticate(transport: Transport, credentials: Credentials, device_id: String)
|
||||
-> BoxFuture<(Transport, Credentials), io::Error>
|
||||
-> Box<Future<Item = (Transport, Credentials), Error = io::Error>>
|
||||
{
|
||||
use protocol::authentication::{APWelcome, ClientResponseEncrypted, CpuFamily, Os};
|
||||
|
||||
|
@ -50,7 +50,7 @@ pub fn authenticate(transport: Transport, credentials: Credentials, device_id: S
|
|||
let cmd = 0xab;
|
||||
let data = packet.write_to_bytes().unwrap();
|
||||
|
||||
transport.send((cmd, data)).and_then(|transport| {
|
||||
Box::new(transport.send((cmd, data)).and_then(|transport| {
|
||||
transport.into_future().map_err(|(err, _stream)| err)
|
||||
}).and_then(|(packet, transport)| {
|
||||
match packet {
|
||||
|
@ -71,5 +71,5 @@ pub fn authenticate(transport: Transport, credentials: Credentials, device_id: S
|
|||
Some((cmd, _)) => panic!("Unexpected packet {:?}", cmd),
|
||||
None => panic!("EOF"),
|
||||
}
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use byteorder::{BigEndian, ByteOrder};
|
||||
use futures::sync::{oneshot, mpsc};
|
||||
use futures::{Async, Poll, BoxFuture, Future};
|
||||
use futures::{Async, Poll, Future};
|
||||
use protobuf;
|
||||
use protocol;
|
||||
use std::collections::HashMap;
|
||||
|
@ -99,7 +99,7 @@ impl MercuryManager {
|
|||
}
|
||||
|
||||
pub fn subscribe<T: Into<String>>(&self, uri: T)
|
||||
-> BoxFuture<mpsc::UnboundedReceiver<MercuryResponse>, MercuryError>
|
||||
-> Box<Future<Item = mpsc::UnboundedReceiver<MercuryResponse>, Error = MercuryError>>
|
||||
{
|
||||
let uri = uri.into();
|
||||
let request = self.request(MercuryRequest {
|
||||
|
@ -110,7 +110,7 @@ impl MercuryManager {
|
|||
});
|
||||
|
||||
let manager = self.clone();
|
||||
request.map(move |response| {
|
||||
Box::new(request.map(move |response| {
|
||||
let (tx, rx) = mpsc::unbounded();
|
||||
|
||||
manager.lock(move |inner| {
|
||||
|
@ -133,7 +133,7 @@ impl MercuryManager {
|
|||
});
|
||||
|
||||
rx
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn dispatch(&self, cmd: u8, mut data: EasyBuf) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crypto::digest::Digest;
|
||||
use crypto::sha1::Sha1;
|
||||
use futures::sync::mpsc;
|
||||
use futures::{Future, Stream, BoxFuture, IntoFuture, Poll, Async};
|
||||
use futures::{Future, Stream, IntoFuture, Poll, Async};
|
||||
use std::io;
|
||||
use std::sync::{RwLock, Arc, Weak};
|
||||
use tokio_core::io::EasyBuf;
|
||||
|
@ -90,7 +90,7 @@ impl Session {
|
|||
|
||||
fn create(handle: &Handle, transport: connection::Transport,
|
||||
config: SessionConfig, cache: Option<Cache>, username: String)
|
||||
-> (Session, BoxFuture<(), io::Error>)
|
||||
-> (Session, Box<Future<Item = (), Error = io::Error>>)
|
||||
{
|
||||
let (sink, stream) = transport.split();
|
||||
|
||||
|
@ -124,8 +124,8 @@ impl Session {
|
|||
.forward(sink).map(|_| ());
|
||||
let receiver_task = DispatchTask(stream, session.weak());
|
||||
|
||||
let task = (receiver_task, sender_task).into_future()
|
||||
.map(|((), ())| ()).boxed();
|
||||
let task = Box::new((receiver_task, sender_task).into_future()
|
||||
.map(|((), ())| ()));
|
||||
|
||||
(session, task)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ extern crate librespot_protocol as protocol;
|
|||
|
||||
pub mod cover;
|
||||
|
||||
use futures::{Future, BoxFuture};
|
||||
use futures::Future;
|
||||
use linear_map::LinearMap;
|
||||
|
||||
use core::mercury::MercuryError;
|
||||
|
@ -57,17 +57,17 @@ pub trait Metadata : Send + Sized + 'static {
|
|||
fn base_url() -> &'static str;
|
||||
fn parse(msg: &Self::Message, session: &Session) -> Self;
|
||||
|
||||
fn get(session: &Session, id: SpotifyId) -> BoxFuture<Self, MercuryError> {
|
||||
fn get(session: &Session, id: SpotifyId) -> Box<Future<Item = Self, Error = MercuryError>> {
|
||||
let uri = format!("{}/{}", Self::base_url(), id.to_base16());
|
||||
let request = session.mercury().get(uri);
|
||||
|
||||
let session = session.clone();
|
||||
request.and_then(move |response| {
|
||||
Box::new(request.and_then(move |response| {
|
||||
let data = response.payload.first().expect("Empty payload");
|
||||
let msg: Self::Message = protobuf::parse_from_bytes(data).unwrap();
|
||||
|
||||
Ok(Self::parse(&msg, &session))
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use crypto::digest::Digest;
|
|||
use crypto::mac::Mac;
|
||||
use crypto;
|
||||
use futures::sync::mpsc;
|
||||
use futures::{Future, Stream, BoxFuture, Poll, Async};
|
||||
use futures::{Future, Stream, Poll, Async};
|
||||
use hyper::server::{Service, NewService, Request, Response, Http};
|
||||
use hyper::{self, Get, Post, StatusCode};
|
||||
use mdns;
|
||||
|
@ -159,7 +159,7 @@ impl Service for Discovery {
|
|||
type Request = Request;
|
||||
type Response = Response;
|
||||
type Error = hyper::Error;
|
||||
type Future = BoxFuture<Response, hyper::Error>;
|
||||
type Future = Box<Future<Item = Response, Error = hyper::Error>>;
|
||||
|
||||
fn call(&self, request: Request) -> Self::Future {
|
||||
let mut params = BTreeMap::new();
|
||||
|
@ -174,7 +174,7 @@ impl Service for Discovery {
|
|||
}
|
||||
|
||||
let this = self.clone();
|
||||
body.fold(Vec::new(), |mut acc, chunk| {
|
||||
Box::new(body.fold(Vec::new(), |mut acc, chunk| {
|
||||
acc.extend_from_slice(chunk.as_ref());
|
||||
Ok::<_, hyper::Error>(acc)
|
||||
}).map(move |body| {
|
||||
|
@ -186,7 +186,7 @@ impl Service for Discovery {
|
|||
(Post, Some("addUser")) => this.handle_add_user(¶ms),
|
||||
_ => this.not_found(),
|
||||
}
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use futures::{Future, BoxFuture};
|
||||
use futures::Future;
|
||||
use serde_json;
|
||||
|
||||
use core::mercury::MercuryError;
|
||||
|
@ -13,14 +13,14 @@ pub struct Token {
|
|||
pub scope: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn get_token(session: &Session, client_id: &str, scopes: &str) -> BoxFuture<Token, MercuryError> {
|
||||
pub fn get_token(session: &Session, client_id: &str, scopes: &str) -> Box<Future<Item = Token, Error = MercuryError>> {
|
||||
let url = format!("hm://keymaster/token/authenticated?client_id={}&scope={}",
|
||||
client_id, scopes);
|
||||
session.mercury().get(url).map(move |response| {
|
||||
Box::new(session.mercury().get(url).map(move |response| {
|
||||
let data = response.payload.first().expect("Empty payload");
|
||||
let data = String::from_utf8(data.clone()).unwrap();
|
||||
let token : Token = serde_json::from_str(&data).unwrap();
|
||||
|
||||
token
|
||||
}).boxed()
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ impl Main {
|
|||
spirc: None,
|
||||
spirc_task: None,
|
||||
shutdown: false,
|
||||
signal: tokio_signal::ctrl_c(&handle).flatten_stream().boxed(),
|
||||
signal: Box::new(tokio_signal::ctrl_c(&handle).flatten_stream()),
|
||||
};
|
||||
|
||||
if setup.enable_discovery {
|
||||
|
|
20
src/spirc.rs
20
src/spirc.rs
|
@ -1,8 +1,6 @@
|
|||
use futures::future;
|
||||
use futures::sink::BoxSink;
|
||||
use futures::stream::BoxStream;
|
||||
use futures::sync::{oneshot, mpsc};
|
||||
use futures::{Future, Stream, Sink, Async, Poll, BoxFuture};
|
||||
use futures::{Future, Stream, Sink, Async, Poll};
|
||||
use protobuf::{self, Message};
|
||||
|
||||
use core::config::ConnectConfig;
|
||||
|
@ -30,10 +28,10 @@ pub struct SpircTask {
|
|||
device: DeviceState,
|
||||
state: State,
|
||||
|
||||
subscription: BoxStream<Frame, MercuryError>,
|
||||
sender: BoxSink<Frame, MercuryError>,
|
||||
subscription: Box<Stream<Item = Frame, Error = MercuryError>>,
|
||||
sender: Box<Sink<SinkItem = Frame, SinkError = MercuryError>>,
|
||||
commands: mpsc::UnboundedReceiver<SpircCommand>,
|
||||
end_of_track: BoxFuture<(), oneshot::Canceled>,
|
||||
end_of_track: Box<Future<Item = (), Error = oneshot::Canceled>>,
|
||||
|
||||
shutdown: bool,
|
||||
session: Session,
|
||||
|
@ -134,10 +132,10 @@ impl Spirc {
|
|||
|
||||
let subscription = session.mercury().subscribe(&uri as &str);
|
||||
let subscription = subscription.map(|stream| stream.map_err(|_| MercuryError)).flatten_stream();
|
||||
let subscription = subscription.map(|response| -> Frame {
|
||||
let subscription = Box::new(subscription.map(|response| -> Frame {
|
||||
let data = response.payload.first().unwrap();
|
||||
protobuf::parse_from_bytes(data).unwrap()
|
||||
}).boxed();
|
||||
}));
|
||||
|
||||
let sender = Box::new(session.mercury().sender(uri).with(|frame: Frame| {
|
||||
Ok(frame.write_to_bytes().unwrap())
|
||||
|
@ -163,7 +161,7 @@ impl Spirc {
|
|||
subscription: subscription,
|
||||
sender: sender,
|
||||
commands: cmd_rx,
|
||||
end_of_track: future::empty().boxed(),
|
||||
end_of_track: Box::new(future::empty()),
|
||||
|
||||
shutdown: false,
|
||||
session: session.clone(),
|
||||
|
@ -238,7 +236,7 @@ impl Future for SpircTask {
|
|||
}
|
||||
Ok(Async::NotReady) => (),
|
||||
Err(oneshot::Canceled) => {
|
||||
self.end_of_track = future::empty().boxed()
|
||||
self.end_of_track = Box::new(future::empty())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -587,7 +585,7 @@ impl SpircTask {
|
|||
self.state.set_status(PlayStatus::kPlayStatusPause);
|
||||
}
|
||||
|
||||
self.end_of_track = end_of_track.boxed();
|
||||
self.end_of_track = Box::new(end_of_track);
|
||||
}
|
||||
|
||||
fn hello(&mut self) {
|
||||
|
|
Loading…
Reference in a new issue