From 60c7f4762f6cbc58b65ca14dd9853d9cd351c62c Mon Sep 17 00:00:00 2001 From: Patrick Auernig Date: Tue, 3 Apr 2018 16:01:23 +0200 Subject: [PATCH] Use default SocketConnection for current platform --- examples/discord_presence/src/main.rs | 6 +----- src/client.rs | 15 ++++++++++----- src/connection/mod.rs | 6 +++--- src/lib.rs | 5 +---- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/examples/discord_presence/src/main.rs b/examples/discord_presence/src/main.rs index 827cfd9..76db7a9 100644 --- a/examples/discord_presence/src/main.rs +++ b/examples/discord_presence/src/main.rs @@ -4,16 +4,12 @@ extern crate discord_rpc_client; use simplelog::*; use std::{thread, time}; use discord_rpc_client::Client as DiscordRPC; -#[cfg(unix)] -use discord_rpc_client::UnixConnection as Connection; -#[cfg(windows)] -use discord_rpc_client::WindowsConnection as Connection; fn main() { TermLogger::init(LevelFilter::Debug, Config::default()).unwrap(); let mut drpc = - DiscordRPC::::new(425407036495495169) + DiscordRPC::new(425407036495495169) .and_then(|rpc| rpc.start()) .expect("Failed to start client"); diff --git a/src/client.rs b/src/client.rs index df52962..69a341e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,11 +1,10 @@ -use connection::Connection; +use connection::{Connection, SocketConnection}; use models::{Handshake, OpCode}; #[cfg(feature = "rich_presence")] use rich_presence::{SetActivityArgs, SetActivity}; use error::Result; -#[derive(Debug)] pub struct Client where T: Connection { @@ -17,9 +16,8 @@ pub struct Client impl Client where T: Connection { - pub fn new(client_id: u64) -> Result { - let socket = T::connect()?; - Ok(Self { version: 1, client_id, socket}) + pub fn with_connection(client_id: u64, socket: T) -> Result { + Ok(Self { version: 1, client_id, socket }) } pub fn start(mut self) -> Result { @@ -45,3 +43,10 @@ impl Client Ok(()) } } + +impl Client { + pub fn new(client_id: u64) -> Result { + let socket = Connection::connect()?; + Self::with_connection(client_id, socket) + } +} diff --git a/src/connection/mod.rs b/src/connection/mod.rs index 891a2db..f76e59b 100644 --- a/src/connection/mod.rs +++ b/src/connection/mod.rs @@ -4,8 +4,8 @@ mod unix; #[cfg(windows)] mod windows; -pub use self::base::Connection; +pub use self::base::Connection as Connection; #[cfg(unix)] -pub use self::unix::UnixConnection; +pub use self::unix::UnixConnection as SocketConnection; #[cfg(windows)] -pub use self::windows::WindowsConnection; +pub use self::windows::WindowsConnection as SocketConnection; diff --git a/src/lib.rs b/src/lib.rs index 1687810..56e123f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,4 @@ pub mod client; pub use client::Client; #[cfg(feature = "rich_presence")] pub use rich_presence::*; -#[cfg(unix)] -pub use connection::UnixConnection; -#[cfg(windows)] -pub use connection::WindowsConnection; +pub use connection::{Connection, SocketConnection};