diff options
| author | Austin Hellyer <[email protected]> | 2016-11-10 07:32:40 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-10 07:32:40 -0800 |
| commit | 3c2c39b8b1bf492ec6d2327630c11eb8e71040b3 (patch) | |
| tree | 9dc36fc238c4c5891cda769aeb3e6cbd0d33609a /src | |
| parent | Correctly shutdown the connection (diff) | |
| download | serenity-3c2c39b8b1bf492ec6d2327630c11eb8e71040b3.tar.xz serenity-3c2c39b8b1bf492ec6d2327630c11eb8e71040b3.zip | |
Properly shutdown on connection Drop
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/connection.rs | 24 | ||||
| -rw-r--r-- | src/lib.rs | 1 |
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>; @@ -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; |