From f456be0309b7f596c85acf6f99bb80fa1d6de3c9 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 3 Mar 2018 10:06:13 -0800 Subject: [PATCH] simplify linked nodes --- src/server/channel.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/server/channel.rs b/src/server/channel.rs index 8cf23ed30..febd5fe77 100644 --- a/src/server/channel.rs +++ b/src/server/channel.rs @@ -95,7 +95,7 @@ impl Future for HttpChannel where T: IoStream, H: HttpHandler + 'sta match result { Ok(Async::Ready(())) | Err(_) => { h1.settings().remove_channel(); - self.node.as_ref().unwrap().remove(); + self.node.as_mut().unwrap().remove(); }, _ => (), } @@ -106,7 +106,7 @@ impl Future for HttpChannel where T: IoStream, H: HttpHandler + 'sta match result { Ok(Async::Ready(())) | Err(_) => { h2.settings().remove_channel(); - self.node.as_ref().unwrap().remove(); + self.node.as_mut().unwrap().remove(); }, _ => (), } @@ -186,13 +186,15 @@ impl Node } } - fn remove(&self) { + fn remove(&mut self) { #[allow(mutable_transmutes)] unsafe { - if let Some(ref prev) = self.prev { + let mut prev = self.prev.take(); + let next = self.next.take(); + + if let Some(ref mut prev) = prev { let p: &mut Node<()> = mem::transmute(prev.as_ref().unwrap()); - let slf: &mut Node = mem::transmute(self); - p.next = slf.next.take(); + p.next = next; } } }