use super::Connector; use crate::common::WindowsPipeTransport; use async_trait::async_trait; use std::ffi::OsString; use std::io; /// Implementation of [`Connector`] to support connecting via a Windows named pipe. pub struct WindowsPipeConnector { addr: OsString, pub(crate) local: bool, } impl WindowsPipeConnector { /// Creates a new connector for a non-local pipe using the given `addr`. pub fn new(addr: impl Into) -> Self { Self { addr: addr.into(), local: false, } } /// Creates a new connector for a local pipe using the given `name`. pub fn local(name: impl Into) -> Self { Self { addr: name.into(), local: true, } } } impl> From for WindowsPipeConnector { fn from(addr: T) -> Self { Self::new(addr) } } #[async_trait] impl Connector for WindowsPipeConnector { type Transport = WindowsPipeTransport; async fn connect(self) -> io::Result { if self.local { let mut full_addr = OsString::from(r"\\.\pipe\"); full_addr.push(self.addr); WindowsPipeTransport::connect(full_addr).await } else { WindowsPipeTransport::connect(self.addr).await } } }