Privatize struct fields

This commit is contained in:
Patrick Auernig 2018-03-22 20:54:18 +01:00
parent 045d7cdf91
commit 43c8a6af5f
6 changed files with 24 additions and 17 deletions

View File

@ -9,8 +9,8 @@ use models::{SetActivityArgs, SetActivity};
#[derive(Debug)]
pub struct Client {
pub client_id: u64,
pub version: u32,
client_id: u64,
version: u32,
socket: UnixStream,
}

View File

@ -12,7 +12,8 @@ extern crate uuid;
#[macro_use]
mod macros;
pub mod models;
mod models;
pub mod client;
pub use models::prelude;
pub use client::Client;

View File

@ -1,12 +1,16 @@
macro_rules! message_func {
[ $name:ident, $type:tt func ] => {
pub fn $name<F: FnOnce($type) -> $type>(mut self, func: F) -> Self {
pub fn $name<F>(mut self, func: F) -> Self
where F: FnOnce($type) -> $type
{
self.$name = Some(func($type::default())); self
}
};
[ $name:ident, String ] => {
pub fn $name<S: Into<String>>(mut self, value: S) -> Self {
pub fn $name<S>(mut self, value: S) -> Self
where S: Into<String>
{
self.$name = Some(value.into()); self
}
};
@ -37,7 +41,7 @@ macro_rules! message_format {
message_format![ @st
( $name $($rest)* ) -> (
#[serde(skip_serializing_if = "Option::is_none")]
pub $field: Option<$type>,
$field: Option<$type>,
$($out)*
)
];

View File

@ -3,9 +3,9 @@ use super::Payload;
#[derive(Debug, Default, Serialize)]
pub struct Handshake {
pub nonce: String,
pub v: u32,
pub client_id: String,
nonce: String,
v: u32,
client_id: String,
}
impl Handshake {

View File

@ -14,9 +14,11 @@ pub use self::set_activity::*;
pub trait Payload: Serialize {}
pub mod prelude {
pub use super::message::Message;
pub use super::command::Command;
pub use super::handshake::Handshake;
#[cfg(feature = "rich_presence")]
pub use super::set_activity::SetActivity;
pub use super::set_activity::{
SetActivity,
SetActivityAssets,
SetActivityParty,
SetActivitySecrets,
SetActivityTimestamps
};
}

View File

@ -1,10 +1,10 @@
use std::process::id as pid;
use models::prelude::Command;
use models::Command;
#[derive(Debug, Default, Serialize)]
pub struct SetActivityArgs {
pub pid: u32,
pub activity: SetActivity,
pid: u32,
activity: SetActivity,
}
impl SetActivityArgs {