|
1 | 1 | use async_std::io::{self, prelude::*};
|
2 | 2 |
|
| 3 | +use std::fmt; |
3 | 4 | use std::pin::Pin;
|
4 | 5 | use std::task::{Context, Poll};
|
5 | 6 |
|
6 | 7 | /// An upgraded HTTP connection.
|
7 |
| -#[derive(Debug, Clone)] |
8 | 8 | pub struct Connection {
|
9 |
| - inner: Pin<Box<dyn Read + Write + Clone + Send + Sync + Unpin + 'static>>, |
| 9 | + inner: Pin<Box<dyn InnerConnection + 'static>>, |
10 | 10 | }
|
11 | 11 |
|
| 12 | +pub(crate) trait InnerConnection: Read + Write + Send + Sync + Unpin {} |
| 13 | +impl<T: Read + Write + Send + Sync + Unpin> InnerConnection for T {} |
| 14 | + |
12 | 15 | impl Read for Connection {
|
13 | 16 | fn poll_read(
|
14 |
| - self: Pin<&mut Self>, |
| 17 | + mut self: Pin<&mut Self>, |
15 | 18 | cx: &mut Context<'_>,
|
16 | 19 | buf: &mut [u8],
|
17 | 20 | ) -> Poll<io::Result<usize>> {
|
18 |
| - let this = self.project(); |
19 |
| - Pin::new(this.inner).poll_read(cx, buf) |
| 21 | + Pin::new(&mut self.inner).poll_read(cx, buf) |
20 | 22 | }
|
21 | 23 | }
|
22 | 24 |
|
23 | 25 | impl Write for Connection {
|
24 | 26 | fn poll_write(
|
25 |
| - self: Pin<&mut Self>, |
| 27 | + mut self: Pin<&mut Self>, |
26 | 28 | cx: &mut Context<'_>,
|
27 | 29 | buf: &[u8],
|
28 | 30 | ) -> Poll<io::Result<usize>> {
|
29 |
| - let this = self.project(); |
30 |
| - Pin::new(this.inner).poll_write(cx, buf) |
| 31 | + Pin::new(&mut self.inner).poll_write(cx, buf) |
| 32 | + } |
| 33 | + |
| 34 | + fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> { |
| 35 | + Pin::new(&mut self.inner).poll_flush(cx) |
31 | 36 | }
|
32 | 37 |
|
33 |
| - fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> { |
34 |
| - let this = self.project(); |
35 |
| - Pin::new(this.inner).poll_flush(cx) |
| 38 | + fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> { |
| 39 | + Pin::new(&mut self.inner).poll_close(cx) |
36 | 40 | }
|
| 41 | +} |
37 | 42 |
|
38 |
| - fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> { |
39 |
| - let this = self.project(); |
40 |
| - Pin::new(this.inner).poll_close(cx) |
| 43 | +impl fmt::Debug for Connection { |
| 44 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 45 | + f.debug_struct("Connection") |
| 46 | + .field("inner", &"Pin<Box<dyn Inner>>") |
| 47 | + .finish() |
41 | 48 | }
|
42 | 49 | }
|
0 commit comments