Remove usage of deprecated BoxFuture, BoxStream and BoxSink

This commit is contained in:
Thomas Bächler 2018-01-21 20:29:31 +01:00
parent 0bdf9aa080
commit 5237203899
8 changed files with 36 additions and 38 deletions

View file

@ -4,7 +4,7 @@ mod handshake;
pub use self::codec::APCodec; pub use self::codec::APCodec;
pub use self::handshake::handshake; pub use self::handshake::handshake;
use futures::{Future, Sink, Stream, BoxFuture}; use futures::{Future, Sink, Stream};
use std::io; use std::io;
use std::net::ToSocketAddrs; use std::net::ToSocketAddrs;
use tokio_core::net::TcpStream; use tokio_core::net::TcpStream;
@ -17,18 +17,18 @@ use version;
pub type Transport = Framed<TcpStream, APCodec>; 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 addr = addr.to_socket_addrs().unwrap().next().unwrap();
let socket = TcpStream::connect(&addr, handle); let socket = TcpStream::connect(&addr, handle);
let connection = socket.and_then(|socket| { let connection = socket.and_then(|socket| {
handshake(socket) handshake(socket)
}); });
connection.boxed() Box::new(connection)
} }
pub fn authenticate(transport: Transport, credentials: Credentials, device_id: String) 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}; 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 cmd = 0xab;
let data = packet.write_to_bytes().unwrap(); 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) transport.into_future().map_err(|(err, _stream)| err)
}).and_then(|(packet, transport)| { }).and_then(|(packet, transport)| {
match packet { match packet {
@ -71,5 +71,5 @@ pub fn authenticate(transport: Transport, credentials: Credentials, device_id: S
Some((cmd, _)) => panic!("Unexpected packet {:?}", cmd), Some((cmd, _)) => panic!("Unexpected packet {:?}", cmd),
None => panic!("EOF"), None => panic!("EOF"),
} }
}).boxed() }))
} }

View file

@ -1,6 +1,6 @@
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use futures::sync::{oneshot, mpsc}; use futures::sync::{oneshot, mpsc};
use futures::{Async, Poll, BoxFuture, Future}; use futures::{Async, Poll, Future};
use protobuf; use protobuf;
use protocol; use protocol;
use std::collections::HashMap; use std::collections::HashMap;
@ -99,7 +99,7 @@ impl MercuryManager {
} }
pub fn subscribe<T: Into<String>>(&self, uri: T) 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 uri = uri.into();
let request = self.request(MercuryRequest { let request = self.request(MercuryRequest {
@ -110,7 +110,7 @@ impl MercuryManager {
}); });
let manager = self.clone(); let manager = self.clone();
request.map(move |response| { Box::new(request.map(move |response| {
let (tx, rx) = mpsc::unbounded(); let (tx, rx) = mpsc::unbounded();
manager.lock(move |inner| { manager.lock(move |inner| {
@ -133,7 +133,7 @@ impl MercuryManager {
}); });
rx rx
}).boxed() }))
} }
pub fn dispatch(&self, cmd: u8, mut data: EasyBuf) { pub fn dispatch(&self, cmd: u8, mut data: EasyBuf) {

View file

@ -1,7 +1,7 @@
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::sha1::Sha1; use crypto::sha1::Sha1;
use futures::sync::mpsc; use futures::sync::mpsc;
use futures::{Future, Stream, BoxFuture, IntoFuture, Poll, Async}; use futures::{Future, Stream, IntoFuture, Poll, Async};
use std::io; use std::io;
use std::sync::{RwLock, Arc, Weak}; use std::sync::{RwLock, Arc, Weak};
use tokio_core::io::EasyBuf; use tokio_core::io::EasyBuf;
@ -90,7 +90,7 @@ impl Session {
fn create(handle: &Handle, transport: connection::Transport, fn create(handle: &Handle, transport: connection::Transport,
config: SessionConfig, cache: Option<Cache>, username: String) config: SessionConfig, cache: Option<Cache>, username: String)
-> (Session, BoxFuture<(), io::Error>) -> (Session, Box<Future<Item = (), Error = io::Error>>)
{ {
let (sink, stream) = transport.split(); let (sink, stream) = transport.split();
@ -124,8 +124,8 @@ impl Session {
.forward(sink).map(|_| ()); .forward(sink).map(|_| ());
let receiver_task = DispatchTask(stream, session.weak()); let receiver_task = DispatchTask(stream, session.weak());
let task = (receiver_task, sender_task).into_future() let task = Box::new((receiver_task, sender_task).into_future()
.map(|((), ())| ()).boxed(); .map(|((), ())| ()));
(session, task) (session, task)
} }

View file

@ -8,7 +8,7 @@ extern crate librespot_protocol as protocol;
pub mod cover; pub mod cover;
use futures::{Future, BoxFuture}; use futures::Future;
use linear_map::LinearMap; use linear_map::LinearMap;
use core::mercury::MercuryError; use core::mercury::MercuryError;
@ -57,17 +57,17 @@ pub trait Metadata : Send + Sized + 'static {
fn base_url() -> &'static str; fn base_url() -> &'static str;
fn parse(msg: &Self::Message, session: &Session) -> Self; 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 uri = format!("{}/{}", Self::base_url(), id.to_base16());
let request = session.mercury().get(uri); let request = session.mercury().get(uri);
let session = session.clone(); 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 data = response.payload.first().expect("Empty payload");
let msg: Self::Message = protobuf::parse_from_bytes(data).unwrap(); let msg: Self::Message = protobuf::parse_from_bytes(data).unwrap();
Ok(Self::parse(&msg, &session)) Ok(Self::parse(&msg, &session))
}).boxed() }))
} }
} }

View file

@ -3,7 +3,7 @@ use crypto::digest::Digest;
use crypto::mac::Mac; use crypto::mac::Mac;
use crypto; use crypto;
use futures::sync::mpsc; 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::server::{Service, NewService, Request, Response, Http};
use hyper::{self, Get, Post, StatusCode}; use hyper::{self, Get, Post, StatusCode};
use mdns; use mdns;
@ -159,7 +159,7 @@ impl Service for Discovery {
type Request = Request; type Request = Request;
type Response = Response; type Response = Response;
type Error = hyper::Error; 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 { fn call(&self, request: Request) -> Self::Future {
let mut params = BTreeMap::new(); let mut params = BTreeMap::new();
@ -174,7 +174,7 @@ impl Service for Discovery {
} }
let this = self.clone(); 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()); acc.extend_from_slice(chunk.as_ref());
Ok::<_, hyper::Error>(acc) Ok::<_, hyper::Error>(acc)
}).map(move |body| { }).map(move |body| {
@ -186,7 +186,7 @@ impl Service for Discovery {
(Post, Some("addUser")) => this.handle_add_user(&params), (Post, Some("addUser")) => this.handle_add_user(&params),
_ => this.not_found(), _ => this.not_found(),
} }
}).boxed() }))
} }
} }

View file

@ -1,4 +1,4 @@
use futures::{Future, BoxFuture}; use futures::Future;
use serde_json; use serde_json;
use core::mercury::MercuryError; use core::mercury::MercuryError;
@ -13,14 +13,14 @@ pub struct Token {
pub scope: Vec<String>, 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={}", let url = format!("hm://keymaster/token/authenticated?client_id={}&scope={}",
client_id, scopes); 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 = response.payload.first().expect("Empty payload");
let data = String::from_utf8(data.clone()).unwrap(); let data = String::from_utf8(data.clone()).unwrap();
let token : Token = serde_json::from_str(&data).unwrap(); let token : Token = serde_json::from_str(&data).unwrap();
token token
}).boxed() }))
} }

View file

@ -264,7 +264,7 @@ impl Main {
spirc: None, spirc: None,
spirc_task: None, spirc_task: None,
shutdown: false, 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 { if setup.enable_discovery {

View file

@ -1,8 +1,6 @@
use futures::future; use futures::future;
use futures::sink::BoxSink;
use futures::stream::BoxStream;
use futures::sync::{oneshot, mpsc}; 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 protobuf::{self, Message};
use core::config::ConnectConfig; use core::config::ConnectConfig;
@ -30,10 +28,10 @@ pub struct SpircTask {
device: DeviceState, device: DeviceState,
state: State, state: State,
subscription: BoxStream<Frame, MercuryError>, subscription: Box<Stream<Item = Frame, Error = MercuryError>>,
sender: BoxSink<Frame, MercuryError>, sender: Box<Sink<SinkItem = Frame, SinkError = MercuryError>>,
commands: mpsc::UnboundedReceiver<SpircCommand>, commands: mpsc::UnboundedReceiver<SpircCommand>,
end_of_track: BoxFuture<(), oneshot::Canceled>, end_of_track: Box<Future<Item = (), Error = oneshot::Canceled>>,
shutdown: bool, shutdown: bool,
session: Session, session: Session,
@ -134,10 +132,10 @@ impl Spirc {
let subscription = session.mercury().subscribe(&uri as &str); let subscription = session.mercury().subscribe(&uri as &str);
let subscription = subscription.map(|stream| stream.map_err(|_| MercuryError)).flatten_stream(); 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(); let data = response.payload.first().unwrap();
protobuf::parse_from_bytes(data).unwrap() protobuf::parse_from_bytes(data).unwrap()
}).boxed(); }));
let sender = Box::new(session.mercury().sender(uri).with(|frame: Frame| { let sender = Box::new(session.mercury().sender(uri).with(|frame: Frame| {
Ok(frame.write_to_bytes().unwrap()) Ok(frame.write_to_bytes().unwrap())
@ -163,7 +161,7 @@ impl Spirc {
subscription: subscription, subscription: subscription,
sender: sender, sender: sender,
commands: cmd_rx, commands: cmd_rx,
end_of_track: future::empty().boxed(), end_of_track: Box::new(future::empty()),
shutdown: false, shutdown: false,
session: session.clone(), session: session.clone(),
@ -238,7 +236,7 @@ impl Future for SpircTask {
} }
Ok(Async::NotReady) => (), Ok(Async::NotReady) => (),
Err(oneshot::Canceled) => { 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.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) { fn hello(&mut self) {