From 5237203899c416b772d5ec797b3fdb911922677c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20B=C3=A4chler?= Date: Sun, 21 Jan 2018 20:29:31 +0100 Subject: [PATCH] Remove usage of deprecated BoxFuture, BoxStream and BoxSink --- core/src/connection/mod.rs | 12 ++++++------ core/src/mercury/mod.rs | 8 ++++---- core/src/session.rs | 8 ++++---- metadata/src/lib.rs | 8 ++++---- src/discovery.rs | 8 ++++---- src/keymaster.rs | 8 ++++---- src/main.rs | 2 +- src/spirc.rs | 20 +++++++++----------- 8 files changed, 36 insertions(+), 38 deletions(-) diff --git a/core/src/connection/mod.rs b/core/src/connection/mod.rs index 1d6f1f07..5df5c097 100644 --- a/core/src/connection/mod.rs +++ b/core/src/connection/mod.rs @@ -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; -pub fn connect(addr: A, handle: &Handle) -> BoxFuture { +pub fn connect(addr: A, handle: &Handle) -> Box> { 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> { 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() + })) } diff --git a/core/src/mercury/mod.rs b/core/src/mercury/mod.rs index 23a3224e..45e12f18 100644 --- a/core/src/mercury/mod.rs +++ b/core/src/mercury/mod.rs @@ -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>(&self, uri: T) - -> BoxFuture, MercuryError> + -> Box, 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) { diff --git a/core/src/session.rs b/core/src/session.rs index 9a45df89..067b685b 100644 --- a/core/src/session.rs +++ b/core/src/session.rs @@ -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, username: String) - -> (Session, BoxFuture<(), io::Error>) + -> (Session, Box>) { 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) } diff --git a/metadata/src/lib.rs b/metadata/src/lib.rs index 3ad5c4e5..f76cd224 100644 --- a/metadata/src/lib.rs +++ b/metadata/src/lib.rs @@ -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 { + fn get(session: &Session, id: SpotifyId) -> Box> { 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() + })) } } diff --git a/src/discovery.rs b/src/discovery.rs index 3eaa5f0a..46f44dd0 100644 --- a/src/discovery.rs +++ b/src/discovery.rs @@ -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; + type Future = Box>; 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() + })) } } diff --git a/src/keymaster.rs b/src/keymaster.rs index 6ed11fd7..e803a959 100644 --- a/src/keymaster.rs +++ b/src/keymaster.rs @@ -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, } -pub fn get_token(session: &Session, client_id: &str, scopes: &str) -> BoxFuture { +pub fn get_token(session: &Session, client_id: &str, scopes: &str) -> Box> { 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() + })) } diff --git a/src/main.rs b/src/main.rs index c6208f2b..2e05b607 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { diff --git a/src/spirc.rs b/src/spirc.rs index 795ba68f..f2265a6e 100644 --- a/src/spirc.rs +++ b/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, - sender: BoxSink, + subscription: Box>, + sender: Box>, commands: mpsc::UnboundedReceiver, - end_of_track: BoxFuture<(), oneshot::Canceled>, + end_of_track: Box>, 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) {