1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 09:42:40 +01:00

remove unnecessary use of unsafe in read_from_io

This commit is contained in:
gnzlbg 2018-06-20 13:14:53 +02:00
parent 2f917f3700
commit da237611cb

View File

@ -1,5 +1,5 @@
use bytes::{BufMut, BytesMut}; use bytes::{BufMut, BytesMut};
use futures::{Async, Poll}; use futures::Poll;
use std::io; use std::io;
use super::IoStream; use super::IoStream;
@ -10,22 +10,8 @@ const HW_BUFFER_SIZE: usize = 32_768;
pub fn read_from_io<T: IoStream>( pub fn read_from_io<T: IoStream>(
io: &mut T, buf: &mut BytesMut, io: &mut T, buf: &mut BytesMut,
) -> Poll<usize, io::Error> { ) -> Poll<usize, io::Error> {
unsafe { if buf.remaining_mut() < LW_BUFFER_SIZE {
if buf.remaining_mut() < LW_BUFFER_SIZE { buf.reserve(HW_BUFFER_SIZE);
buf.reserve(HW_BUFFER_SIZE);
}
match io.read(buf.bytes_mut()) {
Ok(n) => {
buf.advance_mut(n);
Ok(Async::Ready(n))
}
Err(e) => {
if e.kind() == io::ErrorKind::WouldBlock {
Ok(Async::NotReady)
} else {
Err(e)
}
}
}
} }
io.read_buf(buf)
} }