diff --git a/src/client.rs b/src/client.rs index 29b810a..df52962 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,8 +1,9 @@ -use std::io::Result; use connection::Connection; use models::{Handshake, OpCode}; #[cfg(feature = "rich_presence")] use rich_presence::{SetActivityArgs, SetActivity}; +use error::Result; + #[derive(Debug)] pub struct Client diff --git a/src/connection/base.rs b/src/connection/base.rs index 5e8aab4..68fa2ff 100644 --- a/src/connection/base.rs +++ b/src/connection/base.rs @@ -1,7 +1,11 @@ -use std::io::Result; -use std::marker::Sized; -use std::fmt::Debug; +use std::{ + marker::Sized, + fmt::Debug +}; + use models::{Payload, OpCode}; +use error::Result; + pub trait Connection where Self: Sized diff --git a/src/connection/mod.rs b/src/connection/mod.rs index 0b692f6..3f1434c 100644 --- a/src/connection/mod.rs +++ b/src/connection/mod.rs @@ -1,5 +1,4 @@ mod base; - #[cfg(unix)] mod unix; diff --git a/src/connection/unix.rs b/src/connection/unix.rs index a00be9d..a6664e8 100644 --- a/src/connection/unix.rs +++ b/src/connection/unix.rs @@ -1,13 +1,16 @@ -use std::os::unix::net::UnixStream; -use std::io::{Write, Read, Result}; -use std::time; -use std::path::PathBuf; -use std::env; -use std::fmt::Debug; -use models::Payload; +use std::{ + os::unix::net::UnixStream, + io::{Write, Read}, + time, + path::PathBuf, + env, + fmt::Debug +}; -use models::{Message, OpCode}; use super::base::Connection; +use models::{Payload, Message, OpCode}; +use error::Result; + pub struct UnixConnection { socket: UnixStream, diff --git a/src/error.rs b/src/error.rs index a3ec7ae..de09009 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,14 @@ -use std::error::Error as StdError; -use std::result::Result as StdResult; -use std::io::Error as IoError; -use std::fmt; +use std::{ + error::Error as StdError, + io::Error as IoError, + result::Result as StdResult, + fmt::{ + self, + Display, + Formatter + } +}; + #[derive(Debug)] pub enum Error { @@ -9,8 +16,8 @@ pub enum Error { Conversion, } -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl Display for Error { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.write_str(self.description()) } } diff --git a/src/lib.rs b/src/lib.rs index e182547..ed330dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,6 @@ extern crate libc; #[macro_use] mod macros; - mod error; mod utils; mod connection; @@ -20,9 +19,7 @@ mod rich_presence; pub mod client; pub use client::Client; - #[cfg(feature = "rich_presence")] pub use rich_presence::*; - #[cfg(unix)] pub use connection::UnixConnection; diff --git a/src/models/command.rs b/src/models/command.rs index 61c414f..e50f165 100644 --- a/src/models/command.rs +++ b/src/models/command.rs @@ -1,7 +1,9 @@ use serde::Serialize; + use super::Payload; use utils::nonce; + #[derive(Debug, Default, Serialize)] pub struct Command where T: Serialize diff --git a/src/models/handshake.rs b/src/models/handshake.rs index 8fa57e9..95c94bb 100644 --- a/src/models/handshake.rs +++ b/src/models/handshake.rs @@ -1,6 +1,7 @@ use super::Payload; use utils::nonce; + #[derive(Debug, Default, Serialize)] pub struct Handshake { nonce: String, diff --git a/src/models/message.rs b/src/models/message.rs index a348507..a2a3dcf 100644 --- a/src/models/message.rs +++ b/src/models/message.rs @@ -1,9 +1,12 @@ use std::io::{self, Write, Read}; + use byteorder::{WriteBytesExt, ReadBytesExt, LittleEndian}; use serde_json; use serde::Serialize; + use error::{Result, Error}; + #[derive(Debug, Copy, Clone, PartialEq)] pub enum OpCode { Handshake, diff --git a/src/models/mod.rs b/src/models/mod.rs index a71fd92..c87bbf1 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -3,6 +3,7 @@ mod command; mod handshake; use serde::Serialize; + pub use self::message::{Message, OpCode}; pub use self::command::Command; pub use self::handshake::Handshake; diff --git a/src/rich_presence/set_activity.rs b/src/rich_presence/set_activity.rs index e77673d..d027b63 100644 --- a/src/rich_presence/set_activity.rs +++ b/src/rich_presence/set_activity.rs @@ -1,6 +1,7 @@ use models::Command; use utils::pid; + #[derive(Debug, Default, Serialize)] pub struct SetActivityArgs { pid: i32, diff --git a/src/utils.rs b/src/utils.rs index ea4ec92..cabd3cc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,7 @@ use libc::getpid; use uuid::Uuid; + pub fn pid() -> i32 { unsafe { getpid() as i32 } }