diff --git a/proxmox/src/tools/websocket.rs b/proxmox/src/tools/websocket.rs index ccefad47..9fc7103c 100644 --- a/proxmox/src/tools/websocket.rs +++ b/proxmox/src/tools/websocket.rs @@ -106,14 +106,14 @@ pub fn create_frame( Ok(buf) } -pub struct WebSocketWriter { +pub struct WebSocketWriter { writer: W, text: bool, mask: Option<[u8; 4]>, frame: Option<(Vec, usize, usize)>, } -impl WebSocketWriter { +impl WebSocketWriter { pub fn new(mask: Option<[u8; 4]>, text: bool, writer: W) -> WebSocketWriter { WebSocketWriter { writer: writer, @@ -124,13 +124,13 @@ impl WebSocketWriter { } } -impl AsyncWrite for WebSocketWriter { +impl AsyncWrite for WebSocketWriter { fn poll_write( self: Pin<&mut Self>, cx: &mut Context, buf: &[u8], ) -> Poll> { - let this = unsafe { Pin::into_inner_unchecked(self) }; + let this = Pin::get_mut(self); let frametype = match this.text { true => OpCode::Text, @@ -151,8 +151,7 @@ impl AsyncWrite for WebSocketWriter { // we have a frame in any case, so unwrap is ok let (buf, pos, origsize) = this.frame.as_mut().unwrap(); loop { - //let size = unsafe { Pin::new_unchecked(&mut this.writer) }.poll_write(cx, &buf[*pos..]))? - match unsafe { Pin::new_unchecked(&mut this.writer) }.poll_write(cx, &buf[*pos..]) { + match Pin::new(&mut this.writer).poll_write(cx, &buf[*pos..]) { Poll::Ready(Ok(size)) => { *pos += size; if *pos == buf.len() { @@ -167,11 +166,13 @@ impl AsyncWrite for WebSocketWriter { } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - unsafe { self.map_unchecked_mut(|x| &mut x.writer).poll_flush(cx) } + let this = Pin::get_mut(self); + Pin::new(&mut this.writer).poll_flush(cx) } fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - unsafe { self.map_unchecked_mut(|x| &mut x.writer).poll_shutdown(cx) } + let this = Pin::get_mut(self); + Pin::new(&mut this.writer).poll_shutdown(cx) } }