hyper_unix_socket/
stream.rs1use std::io::IoSlice;
2use std::pin::Pin;
3use std::task::{Context, Poll};
4use std::{fmt, io};
5
6use hyper::rt::{Read, ReadBufCursor, Write};
7use hyper_util::client::legacy::connect::{Connected, Connection};
8use hyper_util::rt::TokioIo;
9use tokio::net::UnixStream;
10
11pub struct UnixSocketConnection(TokioIo<UnixStream>);
13
14impl fmt::Debug for UnixSocketConnection {
17 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18 f.debug_tuple("UnixSocketConnection")
19 .field(&self.0)
20 .finish()
21 }
22}
23
24impl From<TokioIo<UnixStream>> for UnixSocketConnection {
25 fn from(inner: TokioIo<UnixStream>) -> Self {
26 Self(inner)
27 }
28}
29
30impl Read for UnixSocketConnection {
31 #[inline]
32 fn poll_read(
33 self: Pin<&mut Self>,
34 cx: &mut Context,
35 buf: ReadBufCursor<'_>,
36 ) -> Poll<Result<(), io::Error>> {
37 Pin::new(&mut Pin::get_mut(self).0).poll_read(cx, buf)
38 }
39}
40
41impl Write for UnixSocketConnection {
42 #[inline]
43 fn poll_write(
44 self: Pin<&mut Self>,
45 cx: &mut Context<'_>,
46 buf: &[u8],
47 ) -> Poll<Result<usize, io::Error>> {
48 Pin::new(&mut Pin::get_mut(self).0).poll_write(cx, buf)
49 }
50
51 #[inline]
52 fn poll_write_vectored(
53 self: Pin<&mut Self>,
54 cx: &mut Context<'_>,
55 bufs: &[IoSlice<'_>],
56 ) -> Poll<Result<usize, io::Error>> {
57 Pin::new(&mut Pin::get_mut(self).0).poll_write_vectored(cx, bufs)
58 }
59
60 #[inline]
61 fn is_write_vectored(&self) -> bool {
62 self.0.is_write_vectored()
63 }
64
65 #[inline]
66 fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
67 Pin::new(&mut Pin::get_mut(self).0).poll_flush(cx)
68 }
69
70 #[inline]
71 fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
72 Pin::new(&mut Pin::get_mut(self).0).poll_shutdown(cx)
73 }
74}
75
76impl Connection for UnixSocketConnection {
77 fn connected(&self) -> Connected {
78 Connected::new()
79 }
80}