Skip to content

Commit cf4f77e

Browse files
dignifiedquireyoshuawuyts
authored andcommitted
get it actually to compile
1 parent 1a993a9 commit cf4f77e

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/upgrade/connection.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,49 @@
11
use async_std::io::{self, prelude::*};
22

3+
use std::fmt;
34
use std::pin::Pin;
45
use std::task::{Context, Poll};
56

67
/// An upgraded HTTP connection.
7-
#[derive(Debug, Clone)]
88
pub struct Connection {
9-
inner: Pin<Box<dyn Read + Write + Clone + Send + Sync + Unpin + 'static>>,
9+
inner: Pin<Box<dyn InnerConnection + 'static>>,
1010
}
1111

12+
pub(crate) trait InnerConnection: Read + Write + Send + Sync + Unpin {}
13+
impl<T: Read + Write + Send + Sync + Unpin> InnerConnection for T {}
14+
1215
impl Read for Connection {
1316
fn poll_read(
14-
self: Pin<&mut Self>,
17+
mut self: Pin<&mut Self>,
1518
cx: &mut Context<'_>,
1619
buf: &mut [u8],
1720
) -> 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)
2022
}
2123
}
2224

2325
impl Write for Connection {
2426
fn poll_write(
25-
self: Pin<&mut Self>,
27+
mut self: Pin<&mut Self>,
2628
cx: &mut Context<'_>,
2729
buf: &[u8],
2830
) -> 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)
3136
}
3237

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)
3640
}
41+
}
3742

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()
4148
}
4249
}

0 commit comments

Comments
 (0)