From 3e74f2b1efd26754350a9145e1b0525d89276db3 Mon Sep 17 00:00:00 2001 From: _ <> Date: Sun, 29 Nov 2020 16:36:59 +0000 Subject: [PATCH] :recycle: Fix unwrap()s in ptth_core. Some were in an unused function, so I removed that function. Some were in graceful_shutdown and can't really be handled. So I made them into "expect"s --- crates/ptth_core/src/graceful_shutdown.rs | 6 +++--- crates/ptth_core/src/http_serde.rs | 18 ------------------ 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/crates/ptth_core/src/graceful_shutdown.rs b/crates/ptth_core/src/graceful_shutdown.rs index 992414e..82bd541 100644 --- a/crates/ptth_core/src/graceful_shutdown.rs +++ b/crates/ptth_core/src/graceful_shutdown.rs @@ -25,7 +25,7 @@ pub fn init () -> oneshot::Receiver <()> { let tx = tx.replace (None); if let Some (tx) = tx { - tx.send (()).unwrap (); + tx.send (()).expect ("Error sending Ctrl-C to program"); } }).expect ("Error setting Ctrl-C handler"); @@ -72,8 +72,8 @@ impl ForcedShutdown { server: F ) -> Result { let fut = async move { - self.rx.await.unwrap (); - self.tx.send (()).unwrap (); + self.rx.await.expect ("Error awaiting graceful shutdown signal"); + self.tx.send (()).expect ("Error forwarding graceful shutdown signal"); let timeout = 5; debug! ("Starting graceful shutdown. Forcing shutdown in {} seconds", timeout); delay_for (Duration::from_secs (timeout)).await; diff --git a/crates/ptth_core/src/http_serde.rs b/crates/ptth_core/src/http_serde.rs index 5276cfe..b2d4970 100644 --- a/crates/ptth_core/src/http_serde.rs +++ b/crates/ptth_core/src/http_serde.rs @@ -154,24 +154,6 @@ pub struct Response { } impl Response { - pub async fn into_bytes (self) -> Vec { - let mut body = match self.body { - None => return Vec::new (), - Some (x) => x, - }; - - let mut result = match self.content_length { - None => Vec::new (), - Some (x) => Vec::with_capacity (x.try_into ().unwrap ()), - }; - - while let Some (Ok (mut chunk)) = body.recv ().await { - result.append (&mut chunk); - } - - result - } - pub fn status_code (&mut self, c: StatusCode) -> &mut Self { self.parts.status_code = c; self