discord-rpc-client/src/connection/windows.rs

34 lines
745 B
Rust
Raw Normal View History

2022-02-03 09:52:53 -05:00
use std::{path::PathBuf, time};
2018-04-02 17:42:57 -04:00
use tokio::net::windows::named_pipe::{ClientOptions, NamedPipeClient};
2018-04-02 17:42:57 -04:00
use super::base::Connection;
use crate::error::Result;
2018-04-02 17:42:57 -04:00
2022-02-03 09:52:53 -05:00
#[derive(Debug)]
2018-04-02 17:42:57 -04:00
pub struct WindowsConnection {
socket: NamedPipeClient,
2018-04-02 17:42:57 -04:00
}
#[async_trait::async_trait]
2018-04-02 17:42:57 -04:00
impl Connection for WindowsConnection {
type Socket = NamedPipeClient;
fn socket(&mut self) -> &mut Self::Socket {
&mut self.socket
2018-04-02 17:42:57 -04:00
}
fn ipc_path() -> PathBuf {
PathBuf::from(r"\\.\pipe\")
2018-04-02 17:42:57 -04:00
}
async fn connect() -> Result<Self> {
let connection_name = Self::socket_path(0);
Ok(Self { socket: ClientOptions::new().open(connection_name)? })
}
async fn disconnect(mut self) -> Result<()> {
Ok(())
2018-04-02 17:42:57 -04:00
}
}