1use futures::channel::mpsc;
2use futures::stream::Stream;
3
4#[test]
5fn unbounded_size_hint() {
6 let (tx, mut rx) = mpsc::unbounded::<u32>();
7 assert_eq!((0, None), rx.size_hint());
8 tx.unbounded_send(1).unwrap();
9 assert_eq!((1, None), rx.size_hint());
10 rx.try_next().unwrap().unwrap();
11 assert_eq!((0, None), rx.size_hint());
12 tx.unbounded_send(2).unwrap();
13 tx.unbounded_send(3).unwrap();
14 assert_eq!((2, None), rx.size_hint());
15 drop(tx);
16 assert_eq!((2, Some(2)), rx.size_hint());
17 rx.try_next().unwrap().unwrap();
18 assert_eq!((1, Some(1)), rx.size_hint());
19 rx.try_next().unwrap().unwrap();
20 assert_eq!((0, Some(0)), rx.size_hint());
21}
22
23#[test]
24fn channel_size_hint() {
25 let (mut tx, mut rx) = mpsc::channel::<u32>(10);
26 assert_eq!((0, None), rx.size_hint());
27 tx.try_send(1).unwrap();
28 assert_eq!((1, None), rx.size_hint());
29 rx.try_next().unwrap().unwrap();
30 assert_eq!((0, None), rx.size_hint());
31 tx.try_send(2).unwrap();
32 tx.try_send(3).unwrap();
33 assert_eq!((2, None), rx.size_hint());
34 drop(tx);
35 assert_eq!((2, Some(2)), rx.size_hint());
36 rx.try_next().unwrap().unwrap();
37 assert_eq!((1, Some(1)), rx.size_hint());
38 rx.try_next().unwrap().unwrap();
39 assert_eq!((0, Some(0)), rx.size_hint());
40}
41