1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use super::Connector;
use crate::common::UnixSocketTransport;
use async_trait::async_trait;
use std::{io, path::PathBuf};

/// Implementation of [`Connector`] to support connecting via a Unix socket.
pub struct UnixSocketConnector {
    path: PathBuf,
}

impl UnixSocketConnector {
    pub fn new(path: impl Into<PathBuf>) -> Self {
        Self { path: path.into() }
    }
}

impl<T: Into<PathBuf>> From<T> for UnixSocketConnector {
    fn from(path: T) -> Self {
        Self::new(path)
    }
}

#[async_trait]
impl Connector for UnixSocketConnector {
    type Transport = UnixSocketTransport;

    async fn connect(self) -> io::Result<Self::Transport> {
        UnixSocketTransport::connect(self.path).await
    }
}