summaryrefslogtreecommitdiffstats
path: root/third_party/rust/futures/tests/object_safety.rs
blob: 30c892f5e6b493177c3fca4a7d6ca2695da27554 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn assert_is_object_safe<T>() {}

#[test]
fn future() {
    // `FutureExt`, `TryFutureExt` and `UnsafeFutureObj` are not object safe.
    use futures::future::{FusedFuture, Future, TryFuture};

    assert_is_object_safe::<&dyn Future<Output = ()>>();
    assert_is_object_safe::<&dyn FusedFuture<Output = ()>>();
    assert_is_object_safe::<&dyn TryFuture<Ok = (), Error = (), Output = Result<(), ()>>>();
}

#[test]
fn stream() {
    // `StreamExt` and `TryStreamExt` are not object safe.
    use futures::stream::{FusedStream, Stream, TryStream};

    assert_is_object_safe::<&dyn Stream<Item = ()>>();
    assert_is_object_safe::<&dyn FusedStream<Item = ()>>();
    assert_is_object_safe::<&dyn TryStream<Ok = (), Error = (), Item = Result<(), ()>>>();
}

#[test]
fn sink() {
    // `SinkExt` is not object safe.
    use futures::sink::Sink;

    assert_is_object_safe::<&dyn Sink<(), Error = ()>>();
}

#[test]
fn io() {
    // `AsyncReadExt`, `AsyncWriteExt`, `AsyncSeekExt` and `AsyncBufReadExt` are not object safe.
    use futures::io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite};

    assert_is_object_safe::<&dyn AsyncRead>();
    assert_is_object_safe::<&dyn AsyncWrite>();
    assert_is_object_safe::<&dyn AsyncSeek>();
    assert_is_object_safe::<&dyn AsyncBufRead>();
}

#[test]
fn task() {
    // `ArcWake`, `SpawnExt` and `LocalSpawnExt` are not object safe.
    use futures::task::{LocalSpawn, Spawn};

    assert_is_object_safe::<&dyn Spawn>();
    assert_is_object_safe::<&dyn LocalSpawn>();
}