1use super::*;
3
4use std::path::Path;
5
6use tokio::net::UnixStream;
7
8#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
10pub struct UnixConnector<P>(P);
11
12impl<P> UnixConnector<P> {
13 pub fn new(path: P) -> Self {
14 Self(path)
15 }
16
17 pub fn get_path(&self) -> &P {
18 &self.0
19 }
20
21 pub fn get_path_mut(&mut self) -> &mut P {
22 &mut self.0
23 }
24}
25
26impl<P, R> Tether<UnixConnector<P>, R>
27where
28 R: Resolver<UnixConnector<P>>,
29 P: AsRef<Path>,
30{
31 pub async fn connect_unix(path: P, resolver: R) -> Result<Self, std::io::Error> {
33 let connector = UnixConnector::new(path);
34 Tether::connect(connector, resolver).await
35 }
36}
37
38impl<P> Connector for UnixConnector<P>
39where
40 P: AsRef<Path>,
41{
42 type Output = UnixStream;
43
44 fn connect(&mut self) -> PinFut<Result<Self::Output, std::io::Error>> {
45 let path = self.0.as_ref().to_path_buf();
46 Box::pin(UnixStream::connect(path))
47 }
48}