Skip to content

Commit 2504013

Browse files
committed
Deprecate boxed methods
These methods have caused far more confusion than they were ever intended to cause, and they're use rarely enough in practice "to success" that they're likely to be removed from any 0.2 release. As a result this commit starts out the removal process by deprecating them and removing usage internally. Closes #228
1 parent 10e48d8 commit 2504013

File tree

13 files changed

+65
-41
lines changed

13 files changed

+65
-41
lines changed

src/future/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ if_std! {
9797
pub use self::join_all::JoinAll as Collect;
9898

9999
/// A type alias for `Box<Future + Send>`
100+
#[doc(hidden)]
101+
#[deprecated(note = "removed without replacement, recommended to use a \
102+
local extension trait or function if needed, more \
103+
details in #228")]
100104
pub type BoxFuture<T, E> = ::std::boxed::Box<Future<Item = T, Error = E> + Send>;
101105

102106
impl<F: ?Sized + Future> Future for ::std::boxed::Box<F> {
@@ -313,6 +317,11 @@ pub trait Future {
313317
/// let a: BoxFuture<i32, i32> = result(Ok(1)).boxed();
314318
/// ```
315319
#[cfg(feature = "use_std")]
320+
#[doc(hidden)]
321+
#[deprecated(note = "removed without replacement, recommended to use a \
322+
local extension trait or function if needed, more \
323+
details in #228")]
324+
#[allow(deprecated)]
316325
fn boxed(self) -> BoxFuture<Self::Item, Self::Error>
317326
where Self: Sized + Send + 'static
318327
{

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ if_std! {
234234
#[doc(hidden)]
235235
#[deprecated(since = "0.1.4", note = "import through the future module instead")]
236236
#[cfg(feature = "with-deprecated")]
237+
#[allow(deprecated)]
237238
pub use future::{BoxFuture, collect, select_all, select_ok};
238239

239240
#[doc(hidden)]

src/stream/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ if_std! {
112112
pub use self::channel::{channel, Sender, Receiver, FutureSender, SendError};
113113

114114
/// A type alias for `Box<Stream + Send>`
115+
#[doc(hidden)]
116+
#[deprecated(note = "removed without replacement, recommended to use a \
117+
local extension trait or function if needed, more \
118+
details in #228")]
115119
pub type BoxStream<T, E> = ::std::boxed::Box<Stream<Item = T, Error = E> + Send>;
116120

117121
impl<S: ?Sized + Stream> Stream for ::std::boxed::Box<S> {
@@ -251,6 +255,11 @@ pub trait Stream {
251255
/// let a: BoxStream<i32, ()> = rx.boxed();
252256
/// ```
253257
#[cfg(feature = "use_std")]
258+
#[doc(hidden)]
259+
#[deprecated(note = "removed without replacement, recommended to use a \
260+
local extension trait or function if needed, more \
261+
details in #228")]
262+
#[allow(deprecated)]
254263
fn boxed(self) -> BoxStream<Self::Item, Self::Error>
255264
where Self: Sized + Send + 'static,
256265
{

src/task_impl/std/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
1010
use std::thread;
1111

1212
use {Future, Stream, Sink, Poll, Async, StartSend, AsyncSink};
13-
use future::BoxFuture;
1413
use super::core;
1514
use super::{BorrowedTask, NotifyHandle, Spawn, spawn, Notify, UnsafeNotify};
1615

@@ -276,7 +275,7 @@ impl<F: Future> Spawn<F> {
276275
// `Spawn<BoxFuture<(), ()>>` so we wouldn't have to box here and
277276
// it'd be more explicit, but unfortunately that currently has a
278277
// link error on nightly: rust-lang/rust#36155
279-
spawn: spawn(self.into_inner().boxed()),
278+
spawn: spawn(Box::new(self.into_inner())),
280279
inner: Arc::new(RunInner {
281280
exec: exec,
282281
mutex: UnparkMutex::new()
@@ -404,7 +403,7 @@ pub trait Executor: Send + Sync + 'static {
404403
/// Units of work submitted to an `Executor`, currently only created
405404
/// internally.
406405
pub struct Run {
407-
spawn: Spawn<BoxFuture<(), ()>>,
406+
spawn: Spawn<Box<Future<Item = (), Error = ()> + Send>>,
408407
inner: Arc<RunInner>,
409408
}
410409

tests/channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ fn sequence() {
2727
fn send(n: u32, sender: mpsc::Sender<u32>)
2828
-> Box<Future<Item=(), Error=()> + Send> {
2929
if n == 0 {
30-
return result(Ok(())).boxed()
30+
return Box::new(result(Ok(())))
3131
}
32-
sender.send(n).map_err(|_| ()).and_then(move |sender| {
32+
Box::new(sender.send(n).map_err(|_| ()).and_then(move |sender| {
3333
send(n - 1, sender)
34-
}).boxed()
34+
}))
3535
}
3636
}
3737

tests/futures_ordered.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ fn works_2() {
3434
let (b_tx, b_rx) = oneshot::channel::<u32>();
3535
let (c_tx, c_rx) = oneshot::channel::<u32>();
3636

37-
let stream = futures_ordered(vec![a_rx.boxed(), b_rx.join(c_rx).map(|(a, b)| a + b).boxed()]);
37+
let stream = futures_ordered(vec![
38+
Box::new(a_rx) as Box<Future<Item = _, Error = _>>,
39+
Box::new(b_rx.join(c_rx).map(|(a, b)| a + b)),
40+
]);
3841

3942
let mut spawn = futures::executor::spawn(stream);
4043
a_tx.send(33).unwrap();
@@ -52,8 +55,8 @@ fn queue_never_unblocked() {
5255
let (c_tx, c_rx) = oneshot::channel::<Box<Any+Send>>();
5356

5457
let stream = futures_ordered(vec![
55-
a_rx.boxed(),
56-
b_rx.select(c_rx).then(|res| Ok(Box::new(res) as Box<Any+Send>)).boxed(),
58+
Box::new(a_rx) as Box<Future<Item = _, Error = _>>,
59+
Box::new(b_rx.select(c_rx).then(|res| Ok(Box::new(res) as Box<Any+Send>))),
5760
]);
5861

5962
let mut spawn = futures::executor::spawn(stream);

tests/futures_unordered.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ fn works_2() {
3333
let (b_tx, b_rx) = oneshot::channel::<u32>();
3434
let (c_tx, c_rx) = oneshot::channel::<u32>();
3535

36-
let stream = futures_unordered(vec![a_rx.boxed(), b_rx.join(c_rx).map(|(a, b)| a + b).boxed()]);
36+
let stream = futures_unordered(vec![
37+
Box::new(a_rx) as Box<Future<Item = _, Error = _>>,
38+
Box::new(b_rx.join(c_rx).map(|(a, b)| a + b)),
39+
]);
3740

3841
let mut spawn = futures::executor::spawn(stream);
3942
a_tx.send(33).unwrap();
@@ -50,8 +53,8 @@ fn finished_future_ok() {
5053
let (c_tx, c_rx) = oneshot::channel::<Box<Any+Send>>();
5154

5255
let stream = futures_unordered(vec![
53-
a_rx.boxed(),
54-
b_rx.select(c_rx).then(|res| Ok(Box::new(res) as Box<Any+Send>)).boxed(),
56+
Box::new(a_rx) as Box<Future<Item = _, Error = _>>,
57+
Box::new(b_rx.select(c_rx).then(|res| Ok(Box::new(res) as Box<Any+Send>))),
5558
]);
5659

5760
let mut spawn = futures::executor::spawn(stream);

tests/mpsc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ fn stress_drop_sender() {
298298
.and_then(|tx| tx.send(Ok(2)))
299299
.and_then(|tx| tx.send(Ok(3)))
300300
.forget();
301-
rx.then(|r| r.unwrap()).boxed()
301+
Box::new(rx.then(|r| r.unwrap()))
302302
}
303303

304304
for _ in 0..10000 {

tests/recurse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use futures::future::{ok, Future};
88
fn lots() {
99
fn doit(n: usize) -> Box<Future<Item=(), Error=()> + Send> {
1010
if n == 0 {
11-
ok(()).boxed()
11+
Box::new(ok(()))
1212
} else {
13-
ok(n - 1).and_then(doit).boxed()
13+
Box::new(ok(n - 1).and_then(doit))
1414
}
1515
}
1616

tests/select_all.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use futures::future::*;
55
#[test]
66
fn smoke() {
77
let v = vec![
8-
ok(1).boxed(),
9-
err(2).boxed(),
10-
ok(3).boxed(),
8+
ok(1),
9+
err(2),
10+
ok(3),
1111
];
1212

1313
let (i, idx, v) = select_all(v).wait().ok().unwrap();

tests/select_ok.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use futures::future::*;
55
#[test]
66
fn ignore_err() {
77
let v = vec![
8-
err(1).boxed(),
9-
err(2).boxed(),
10-
ok(3).boxed(),
11-
ok(4).boxed(),
8+
err(1),
9+
err(2),
10+
ok(3),
11+
ok(4),
1212
];
1313

1414
let (i, v) = select_ok(v).wait().ok().unwrap();
@@ -25,9 +25,9 @@ fn ignore_err() {
2525
#[test]
2626
fn last_err() {
2727
let v = vec![
28-
ok(1).boxed(),
29-
err(2).boxed(),
30-
err(3).boxed(),
28+
ok(1),
29+
err(2),
30+
err(3),
3131
];
3232

3333
let (i, v) = select_ok(v).wait().ok().unwrap();

tests/sink.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ fn mpsc_blocking_start_send() {
133133
// until a oneshot is completed
134134
fn with_flush() {
135135
let (tx, rx) = oneshot::channel();
136-
let mut block = rx.boxed();
136+
let mut block = Box::new(rx) as Box<Future<Item = _, Error = _>>;
137137
let mut sink = Vec::new().with(|elem| {
138-
mem::replace(&mut block, ok(()).boxed())
138+
mem::replace(&mut block, Box::new(ok(())))
139139
.map(move |_| elem + 1).map_err(|_| -> () { panic!() })
140140
});
141141

tests/stream.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ extern crate futures;
44
use futures::{Async, Future, Poll, Sink, Stream};
55
use futures::executor;
66
use futures::future::{err, ok};
7-
use futures::stream::{empty, iter, poll_fn, BoxStream, Peekable};
7+
use futures::stream::{empty, iter, poll_fn, Peekable};
88
use futures::sync::oneshot;
99
use futures::sync::mpsc;
1010

1111
mod support;
1212
use support::*;
1313

1414

15-
fn list() -> BoxStream<i32, u32> {
15+
fn list() -> Box<Stream<Item=i32, Error=u32> + Send> {
1616
let (tx, rx) = mpsc::channel(1);
1717
tx.send(Ok(1))
1818
.and_then(|tx| tx.send(Ok(2)))
1919
.and_then(|tx| tx.send(Ok(3)))
2020
.forget();
21-
rx.then(|r| r.unwrap()).boxed()
21+
Box::new(rx.then(|r| r.unwrap()))
2222
}
2323

24-
fn err_list() -> BoxStream<i32, u32> {
24+
fn err_list() -> Box<Stream<Item=i32, Error=u32> + Send> {
2525
let (tx, rx) = mpsc::channel(1);
2626
tx.send(Ok(1))
2727
.and_then(|tx| tx.send(Ok(2)))
2828
.and_then(|tx| tx.send(Err(3)))
2929
.forget();
30-
rx.then(|r| r.unwrap()).boxed()
30+
Box::new(rx.then(|r| r.unwrap()))
3131
}
3232

3333
#[test]
@@ -173,8 +173,8 @@ fn buffered() {
173173
let (a, b) = oneshot::channel::<u32>();
174174
let (c, d) = oneshot::channel::<u32>();
175175

176-
tx.send(b.map_err(|_| ()).boxed())
177-
.and_then(|tx| tx.send(d.map_err(|_| ()).boxed()))
176+
tx.send(Box::new(b.map_err(|_| ())) as Box<Future<Item = _, Error = _> + Send>)
177+
.and_then(|tx| tx.send(Box::new(d.map_err(|_| ()))))
178178
.forget();
179179

180180
let mut rx = rx.buffered(2);
@@ -191,8 +191,8 @@ fn buffered() {
191191
let (a, b) = oneshot::channel::<u32>();
192192
let (c, d) = oneshot::channel::<u32>();
193193

194-
tx.send(b.map_err(|_| ()).boxed())
195-
.and_then(|tx| tx.send(d.map_err(|_| ()).boxed()))
194+
tx.send(Box::new(b.map_err(|_| ())) as Box<Future<Item = _, Error = _> + Send>)
195+
.and_then(|tx| tx.send(Box::new(d.map_err(|_| ()))))
196196
.forget();
197197

198198
let mut rx = rx.buffered(1);
@@ -212,8 +212,8 @@ fn unordered() {
212212
let (a, b) = oneshot::channel::<u32>();
213213
let (c, d) = oneshot::channel::<u32>();
214214

215-
tx.send(b.map_err(|_| ()).boxed())
216-
.and_then(|tx| tx.send(d.map_err(|_| ()).boxed()))
215+
tx.send(Box::new(b.map_err(|_| ())) as Box<Future<Item = _, Error = _> + Send>)
216+
.and_then(|tx| tx.send(Box::new(d.map_err(|_| ()))))
217217
.forget();
218218

219219
let mut rx = rx.buffer_unordered(2);
@@ -229,8 +229,8 @@ fn unordered() {
229229
let (a, b) = oneshot::channel::<u32>();
230230
let (c, d) = oneshot::channel::<u32>();
231231

232-
tx.send(b.map_err(|_| ()).boxed())
233-
.and_then(|tx| tx.send(d.map_err(|_| ()).boxed()))
232+
tx.send(Box::new(b.map_err(|_| ())) as Box<Future<Item = _, Error = _> + Send>)
233+
.and_then(|tx| tx.send(Box::new(d.map_err(|_| ()))))
234234
.forget();
235235

236236
// We don't even get to see `c` until `a` completes.
@@ -261,7 +261,7 @@ fn zip() {
261261
#[test]
262262
fn peek() {
263263
struct Peek {
264-
inner: Peekable<BoxStream<i32, u32>>
264+
inner: Peekable<Box<Stream<Item = i32, Error =u32> + Send>>
265265
}
266266

267267
impl Future for Peek {

0 commit comments

Comments
 (0)