diff --git a/examples/server.rs b/examples/server.rs index 148d0a2..299b472 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -86,7 +86,7 @@ fn main() { .filter(|&(&k, _)| k != addr) .map(|(_, v)| v); for tx in iter { - tx.send(message.clone()).unwrap(); + tx.unbounded_send(message.clone()).unwrap(); } Ok(()) }); diff --git a/src/connect.rs b/src/connect.rs index 24e442b..3472bae 100644 --- a/src/connect.rs +++ b/src/connect.rs @@ -9,8 +9,7 @@ use self::tokio_core::net::TcpStream; use self::tokio_core::reactor::Remote; use self::tokio_dns::tcp_connect; -use futures::future; -use futures::{Future, BoxFuture}; +use futures::{future, Future}; use tungstenite::Error; use tungstenite::client::url_mode; use tungstenite::handshake::client::Response; @@ -36,8 +35,7 @@ mod encryption { use std::io::{Read, Write, Result as IoResult}; - use futures::{Future, BoxFuture}; - use futures::future; + use futures::{future, Future}; use tungstenite::Error; use tungstenite::stream::Mode; @@ -53,16 +51,17 @@ mod encryption { } } - pub fn wrap_stream(socket: TcpStream, domain: String, mode: Mode) -> BoxFuture { + pub fn wrap_stream(socket: TcpStream, domain: String, mode: Mode) + -> Box> + { match mode { - Mode::Plain => future::ok(StreamSwitcher::Plain(socket)).boxed(), + Mode::Plain => Box::new(future::ok(StreamSwitcher::Plain(socket))), Mode::Tls => { - future::result(TlsConnector::builder()) - .and_then(move |builder| future::result(builder.build())) - .and_then(move |connector| connector.connect_async(&domain, socket)) - .map(|s| StreamSwitcher::Tls(s)) - .map_err(|e| Error::Tls(e)) - .boxed() + Box::new(future::result(TlsConnector::builder()) + .and_then(move |builder| future::result(builder.build())) + .and_then(move |connector| connector.connect_async(&domain, socket)) + .map(|s| StreamSwitcher::Tls(s)) + .map_err(|e| Error::Tls(e))) } } } @@ -72,18 +71,19 @@ mod encryption { mod encryption { use super::tokio_core::net::TcpStream; - use futures::{Future, BoxFuture}; - use futures::future; + use futures::{future, Future}; use tungstenite::Error; use tungstenite::stream::Mode; pub type AutoStream = TcpStream; - pub fn wrap_stream(socket: TcpStream, _domain: String, mode: Mode) -> BoxFuture { + pub fn wrap_stream(socket: TcpStream, _domain: String, mode: Mode) + -> Box> + { match mode { - Mode::Plain => future::ok(socket).boxed(), - Mode::Tls => future::err(Error::Url("TLS support not compiled in.".into())).boxed(), + Mode::Plain => Box::new(future::ok(socket)), + Mode::Tls => Box::new(future::err(Error::Url("TLS support not compiled in.".into()))), } } } @@ -92,7 +92,7 @@ use self::encryption::{AutoStream, wrap_stream}; /// Connect to a given URL. pub fn connect_async(request: R, handle: Remote) - -> BoxFuture<(WebSocketStream, Response), Error> + -> Box, Response), Error=Error>> where R: Into> { @@ -101,21 +101,20 @@ where // Make sure we check domain and mode first. URL must be valid. let mode = match url_mode(&request.url) { Ok(m) => m, - Err(e) => return future::err(e.into()).boxed(), + Err(e) => return Box::new(future::err(e.into())), }; let domain = match request.url.host_str() { Some(d) => d.to_string(), - None => return future::err(Error::Url("No host name in the URL".into())).boxed(), + None => return Box::new(future::err(Error::Url("No host name in the URL".into()))), }; let port = request.url.port_or_known_default().expect("Bug: port unknown"); - tcp_connect((domain.as_str(), port), handle).map_err(|e| e.into()) - .and_then(move |socket| wrap_stream(socket, domain, mode)) - .and_then(|mut stream| { - NoDelay::set_nodelay(&mut stream, true) - .map(move |()| stream) - .map_err(|e| e.into()) - }) - .and_then(move |stream| client_async(request, stream)) - .boxed() + Box::new(tcp_connect((domain.as_str(), port), handle).map_err(|e| e.into()) + .and_then(move |socket| wrap_stream(socket, domain, mode)) + .and_then(|mut stream| { + NoDelay::set_nodelay(&mut stream, true) + .map(move |()| stream) + .map_err(|e| e.into()) + }) + .and_then(move |stream| client_async(request, stream))) }