diff options
| author | Edward Yang <[email protected]> | 2017-10-16 07:29:39 -0500 |
|---|---|---|
| committer | alex <[email protected]> | 2017-10-16 14:29:39 +0200 |
| commit | fcc4e2ce2e523248ed33c9f4853d3485cbc9b6e6 (patch) | |
| tree | 64814115455d591450cb55eed3ed7635de3973d2 /src | |
| parent | Hash and do equality on just the id for `User` (diff) | |
| download | serenity-fcc4e2ce2e523248ed33c9f4853d3485cbc9b6e6.tar.xz serenity-fcc4e2ce2e523248ed33c9f4853d3485cbc9b6e6.zip | |
Use update syntax for Shard (#195)
Diffstat (limited to 'src')
| -rw-r--r-- | src/gateway/shard.rs | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/src/gateway/shard.rs b/src/gateway/shard.rs index fbe1572..f3c072c 100644 --- a/src/gateway/shard.rs +++ b/src/gateway/shard.rs @@ -128,14 +128,6 @@ impl Shard { -> Result<Shard> { let client = connect(&*ws_url.lock().unwrap())?; - let current_presence = (None, OnlineStatus::Online, false); - let heartbeat_instants = (None, None); - let heartbeat_interval = None; - let last_heartbeat_acknowledged = true; - let seq = 0; - let stage = ConnectionStage::Handshake; - let session_id = None; - Ok(feature_voice! { { let (tx, rx) = mpsc::channel(); @@ -144,32 +136,20 @@ impl Shard { Shard { client, - current_presence, - heartbeat_instants, - heartbeat_interval, - last_heartbeat_acknowledged, - seq, - stage, token, - session_id, shard_info, ws_url, manager: VoiceManager::new(tx, user.id), manager_rx: rx, + .. Default::default() } } else { Shard { client, - current_presence, - heartbeat_instants, - heartbeat_interval, - last_heartbeat_acknowledged, - seq, - stage, token, - session_id, shard_info, ws_url, + .. Default::default() } } }) @@ -1043,3 +1023,30 @@ fn build_gateway_url(base: &str) -> Result<Url> { Url::parse(&format!("{}?v={}", base, constants::GATEWAY_VERSION)) .map_err(|_| Error::Gateway(GatewayError::BuildingUrl)) } + +impl Default for Shard { + fn default() -> Self { + #[cfg(feature = "voice")] + let (tx, rx) = mpsc::channel(); + #[cfg(feature = "voice")] + let user = http::get_current_user().unwrap(); + + Shard { + client: connect(&String::new()).unwrap(), + current_presence: (None, OnlineStatus::Online, false), + heartbeat_instants: (None, None), + heartbeat_interval: None, + last_heartbeat_acknowledged: true, + seq: 0, + stage: ConnectionStage::Handshake, + token: Arc::new(Mutex::new(String::new())), + session_id: None, + shard_info: [0; 2], + ws_url: Arc::new(Mutex::new(String::new())), + #[cfg(feature = "voice")] + manager: VoiceManager::new(tx, user.id), + #[cfg(feature = "voice")] + manager_rx: rx, + } + } +} |