diff --git a/src/client/pipeline.rs b/src/client/pipeline.rs index c2caf83c..de1ff128 100644 --- a/src/client/pipeline.rs +++ b/src/client/pipeline.rs @@ -317,9 +317,6 @@ impl Pipeline { if self.conn.is_none() { return Ok(Async::Ready(None)); } - let conn: &mut Connection = - unsafe { &mut *(self.conn.as_mut().unwrap() as *mut _) }; - let mut need_run = false; // need write? @@ -337,6 +334,9 @@ impl Pipeline { // need read? if self.parser.is_some() { + let conn: &mut Connection = + unsafe { &mut *(self.conn.as_mut().unwrap() as *mut _) }; + loop { match self .parser diff --git a/src/extensions.rs b/src/extensions.rs index 1c64623f..7fdd142b 100644 --- a/src/extensions.rs +++ b/src/extensions.rs @@ -48,7 +48,6 @@ impl Extensions { /// If a extension of this type existed, it will be returned. pub fn remove(&mut self) -> Option { self.map.remove(&TypeId::of::()).and_then(|boxed| { - //TODO: we can use unsafe and remove double checking the type id (boxed as Box) .downcast() .ok() diff --git a/src/ws/client.rs b/src/ws/client.rs index 7cf0095d..5087c885 100644 --- a/src/ws/client.rs +++ b/src/ws/client.rs @@ -1,5 +1,5 @@ //! Http client request -use std::cell::UnsafeCell; +use std::cell::RefCell; use std::rc::Rc; use std::time::Duration; use std::{fmt, io, str}; @@ -422,7 +422,7 @@ impl Future for ClientHandshake { closed: false, }; - let inner = Rc::new(UnsafeCell::new(inner)); + let inner = Rc::new(RefCell::new(inner)); Ok(Async::Ready(( ClientReader { inner: Rc::clone(&inner), @@ -435,7 +435,7 @@ impl Future for ClientHandshake { /// Websocket reader client pub struct ClientReader { - inner: Rc>, + inner: Rc>, max_size: usize, } @@ -451,7 +451,7 @@ impl Stream for ClientReader { fn poll(&mut self) -> Poll, Self::Error> { let max_size = self.max_size; - let inner: &mut Inner = unsafe { &mut *self.inner.get() }; + let mut inner = self.inner.borrow_mut(); if inner.closed { return Ok(Async::Ready(None)); } @@ -507,14 +507,14 @@ impl Stream for ClientReader { /// Websocket writer client pub struct ClientWriter { - inner: Rc>, + inner: Rc>, } impl ClientWriter { /// Write payload #[inline] fn write(&mut self, mut data: Binary) { - let inner: &mut Inner = unsafe { &mut *self.inner.get() }; + let inner = self.inner.borrow_mut(); if !inner.closed { let _ = inner.tx.unbounded_send(data.take()); } else {