aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-10 07:32:40 -0800
committerAustin Hellyer <[email protected]>2016-11-10 07:32:40 -0800
commit3c2c39b8b1bf492ec6d2327630c11eb8e71040b3 (patch)
tree9dc36fc238c4c5891cda769aeb3e6cbd0d33609a /src
parentCorrectly shutdown the connection (diff)
downloadserenity-3c2c39b8b1bf492ec6d2327630c11eb8e71040b3.tar.xz
serenity-3c2c39b8b1bf492ec6d2327630c11eb8e71040b3.zip
Properly shutdown on connection Drop
Diffstat (limited to 'src')
-rw-r--r--src/client/connection.rs24
-rw-r--r--src/lib.rs1
2 files changed, 25 insertions, 0 deletions
diff --git a/src/client/connection.rs b/src/client/connection.rs
index fd06160..1ba3341 100644
--- a/src/client/connection.rs
+++ b/src/client/connection.rs
@@ -456,6 +456,30 @@ impl Connection {
}
}
+impl Drop for Connection {
+ fn drop(&mut self) {
+ match self.shutdown() {
+ Ok(()) => {
+ if let Some([shard, shards]) = self.shard_info {
+ println!("Correctly shutdown shard {}/{}", shard, shards - 1);
+ } else {
+ println!("Correctly shutdown connection");
+ }
+ },
+ Err(why) => {
+ if let Some([shard, shards]) = self.shard_info {
+ println!("Failed to shutdown shard {}/{}: {:?}",
+ shard,
+ shards - 1,
+ why);
+ } else {
+ println!("Failed to shutdown connection: {:?}", why);
+ }
+ }
+ }
+ }
+}
+
trait ReceiverExt {
fn recv_json<F, T>(&mut self, decode: F) -> Result<T>
where F: FnOnce(Value) -> Result<T>;
diff --git a/src/lib.rs b/src/lib.rs
index 689009c..57f12f6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -76,6 +76,7 @@
//! [state docs]: ext/state/index.html
#![allow(doc_markdown, unknown_lints)]
#![allow(dead_code)]
+#![feature(slice_patterns)]
#[macro_use]
extern crate bitflags;