1 #![warn(rust_2018_idioms)]
2 #![cfg(feature = "full")]
3 
4 use tokio::io::{split, AsyncRead, AsyncWrite, ReadHalf, WriteHalf};
5 
6 use std::io;
7 use std::pin::Pin;
8 use std::task::{Context, Poll};
9 
10 struct RW;
11 
12 impl AsyncRead for RW {
poll_read( self: Pin<&mut Self>, _cx: &mut Context<'_>, _buf: &mut [u8], ) -> Poll<io::Result<usize>>13     fn poll_read(
14         self: Pin<&mut Self>,
15         _cx: &mut Context<'_>,
16         _buf: &mut [u8],
17     ) -> Poll<io::Result<usize>> {
18         Poll::Ready(Ok(1))
19     }
20 }
21 
22 impl AsyncWrite for RW {
poll_write( self: Pin<&mut Self>, _cx: &mut Context<'_>, _buf: &[u8], ) -> Poll<Result<usize, io::Error>>23     fn poll_write(
24         self: Pin<&mut Self>,
25         _cx: &mut Context<'_>,
26         _buf: &[u8],
27     ) -> Poll<Result<usize, io::Error>> {
28         Poll::Ready(Ok(1))
29     }
30 
poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>>31     fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
32         Poll::Ready(Ok(()))
33     }
34 
poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>>35     fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
36         Poll::Ready(Ok(()))
37     }
38 }
39 
40 #[test]
is_send_and_sync()41 fn is_send_and_sync() {
42     fn assert_bound<T: Send + Sync>() {}
43 
44     assert_bound::<ReadHalf<RW>>();
45     assert_bound::<WriteHalf<RW>>();
46 }
47 
48 #[test]
split_stream_id()49 fn split_stream_id() {
50     let (r1, w1) = split(RW);
51     let (r2, w2) = split(RW);
52     assert_eq!(r1.is_pair_of(&w1), true);
53     assert_eq!(r1.is_pair_of(&w2), false);
54     assert_eq!(r2.is_pair_of(&w2), true);
55     assert_eq!(r2.is_pair_of(&w1), false);
56 }
57 
58 #[test]
unsplit_ok()59 fn unsplit_ok() {
60     let (r, w) = split(RW);
61     r.unsplit(w);
62 }
63 
64 #[test]
65 #[should_panic]
unsplit_err1()66 fn unsplit_err1() {
67     let (r, _) = split(RW);
68     let (_, w) = split(RW);
69     r.unsplit(w);
70 }
71 
72 #[test]
73 #[should_panic]
unsplit_err2()74 fn unsplit_err2() {
75     let (_, w) = split(RW);
76     let (r, _) = split(RW);
77     r.unsplit(w);
78 }
79