1 | fn assert_is_object_safe<T>() {} |
2 | |
3 | #[test] |
4 | fn future() { |
5 | // `FutureExt`, `TryFutureExt` and `UnsafeFutureObj` are not object safe. |
6 | use futures::future::{FusedFuture, Future, TryFuture}; |
7 | |
8 | assert_is_object_safe::<&dyn Future<Output = ()>>(); |
9 | assert_is_object_safe::<&dyn FusedFuture<Output = ()>>(); |
10 | assert_is_object_safe::<&dyn TryFuture<Ok = (), Error = (), Output = Result<(), ()>>>(); |
11 | } |
12 | |
13 | #[test] |
14 | fn stream() { |
15 | // `StreamExt` and `TryStreamExt` are not object safe. |
16 | use futures::stream::{FusedStream, Stream, TryStream}; |
17 | |
18 | assert_is_object_safe::<&dyn Stream<Item = ()>>(); |
19 | assert_is_object_safe::<&dyn FusedStream<Item = ()>>(); |
20 | assert_is_object_safe::<&dyn TryStream<Ok = (), Error = (), Item = Result<(), ()>>>(); |
21 | } |
22 | |
23 | #[test] |
24 | fn sink() { |
25 | // `SinkExt` is not object safe. |
26 | use futures::sink::Sink; |
27 | |
28 | assert_is_object_safe::<&dyn Sink<(), Error = ()>>(); |
29 | } |
30 | |
31 | #[test] |
32 | fn io() { |
33 | // `AsyncReadExt`, `AsyncWriteExt`, `AsyncSeekExt` and `AsyncBufReadExt` are not object safe. |
34 | use futures::io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite}; |
35 | |
36 | assert_is_object_safe::<&dyn AsyncRead>(); |
37 | assert_is_object_safe::<&dyn AsyncWrite>(); |
38 | assert_is_object_safe::<&dyn AsyncSeek>(); |
39 | assert_is_object_safe::<&dyn AsyncBufRead>(); |
40 | } |
41 | |
42 | #[test] |
43 | fn task() { |
44 | // `ArcWake`, `SpawnExt` and `LocalSpawnExt` are not object safe. |
45 | use futures::task::{LocalSpawn, Spawn}; |
46 | |
47 | assert_is_object_safe::<&dyn Spawn>(); |
48 | assert_is_object_safe::<&dyn LocalSpawn>(); |
49 | } |
50 | |