distant_net/client/builder/
windows.rs1use std::ffi::OsString;
2use std::io;
3
4use async_trait::async_trait;
5
6use super::Connector;
7use crate::common::WindowsPipeTransport;
8
9pub struct WindowsPipeConnector {
11 addr: OsString,
12 pub(crate) local: bool,
13}
14
15impl WindowsPipeConnector {
16 pub fn new(addr: impl Into<OsString>) -> Self {
18 Self {
19 addr: addr.into(),
20 local: false,
21 }
22 }
23
24 pub fn local(name: impl Into<OsString>) -> Self {
26 Self {
27 addr: name.into(),
28 local: true,
29 }
30 }
31}
32
33impl<T: Into<OsString>> From<T> for WindowsPipeConnector {
34 fn from(addr: T) -> Self {
35 Self::new(addr)
36 }
37}
38
39#[async_trait]
40impl Connector for WindowsPipeConnector {
41 type Transport = WindowsPipeTransport;
42
43 async fn connect(self) -> io::Result<Self::Transport> {
44 if self.local {
45 let mut full_addr = OsString::from(r"\\.\pipe\");
46 full_addr.push(self.addr);
47 WindowsPipeTransport::connect(full_addr).await
48 } else {
49 WindowsPipeTransport::connect(self.addr).await
50 }
51 }
52}