Skip to content

Commit 17980ef

Browse files
committed
Minor clean up futures-io
1 parent 6f16a1b commit 17980ef

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

futures-io/src/lib.rs

+29-30
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121

2222
#[cfg(feature = "std")]
2323
mod if_std {
24-
use futures_core::task::{Context, Poll};
2524
use std::cmp;
26-
use std::io as StdIo;
25+
use std::io;
2726
use std::ops::DerefMut;
2827
use std::pin::Pin;
2928
use std::ptr;
29+
use std::task::{Context, Poll};
3030

3131
// Re-export some types from `std::io` so that users don't have to deal
3232
// with conflicts when `use`ing `futures::io` and `std::io`.
3333
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
34-
pub use self::StdIo::{
34+
pub use io::{
3535
Error as Error,
3636
ErrorKind as ErrorKind,
3737
Result as Result,
@@ -147,8 +147,8 @@ mod if_std {
147147
fn poll_read_vectored(self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>])
148148
-> Poll<Result<usize>>
149149
{
150-
if let Some(ref mut first_iovec) = bufs.get_mut(0) {
151-
self.poll_read(cx, first_iovec)
150+
if let Some(first_iovec) = bufs.get_mut(0) {
151+
self.poll_read(cx, &mut **first_iovec)
152152
} else {
153153
// `bufs` is empty.
154154
Poll::Ready(Ok(0))
@@ -208,8 +208,8 @@ mod if_std {
208208
fn poll_write_vectored(self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>])
209209
-> Poll<Result<usize>>
210210
{
211-
if let Some(ref first_iovec) = bufs.get(0) {
212-
self.poll_write(cx, &*first_iovec)
211+
if let Some(first_iovec) = bufs.get(0) {
212+
self.poll_write(cx, &**first_iovec)
213213
} else {
214214
// `bufs` is empty.
215215
Poll::Ready(Ok(0))
@@ -390,7 +390,7 @@ mod if_std {
390390
}
391391
}
392392

393-
/// `unsafe` because the `StdIo::Read` type must not access the buffer
393+
/// `unsafe` because the `io::Read` type must not access the buffer
394394
/// before reading data into it.
395395
macro_rules! unsafe_delegate_async_read_to_stdio {
396396
() => {
@@ -401,13 +401,13 @@ mod if_std {
401401
fn poll_read(mut self: Pin<&mut Self>, _: &mut Context<'_>, buf: &mut [u8])
402402
-> Poll<Result<usize>>
403403
{
404-
Poll::Ready(StdIo::Read::read(&mut *self, buf))
404+
Poll::Ready(io::Read::read(&mut *self, buf))
405405
}
406406

407407
fn poll_read_vectored(mut self: Pin<&mut Self>, _: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>])
408408
-> Poll<Result<usize>>
409409
{
410-
Poll::Ready(StdIo::Read::read_vectored(&mut *self, bufs))
410+
Poll::Ready(io::Read::read_vectored(&mut *self, bufs))
411411
}
412412
}
413413
}
@@ -416,15 +416,15 @@ mod if_std {
416416
unsafe_delegate_async_read_to_stdio!();
417417
}
418418

419-
impl AsyncRead for StdIo::Repeat {
419+
impl AsyncRead for io::Repeat {
420420
unsafe_delegate_async_read_to_stdio!();
421421
}
422422

423-
impl AsyncRead for StdIo::Empty {
423+
impl AsyncRead for io::Empty {
424424
unsafe_delegate_async_read_to_stdio!();
425425
}
426426

427-
impl<T: AsRef<[u8]> + Unpin> AsyncRead for StdIo::Cursor<T> {
427+
impl<T: AsRef<[u8]> + Unpin> AsyncRead for io::Cursor<T> {
428428
unsafe_delegate_async_read_to_stdio!();
429429
}
430430

@@ -491,17 +491,17 @@ mod if_std {
491491
fn poll_write(mut self: Pin<&mut Self>, _: &mut Context<'_>, buf: &[u8])
492492
-> Poll<Result<usize>>
493493
{
494-
Poll::Ready(StdIo::Write::write(&mut *self, buf))
494+
Poll::Ready(io::Write::write(&mut *self, buf))
495495
}
496496

497497
fn poll_write_vectored(mut self: Pin<&mut Self>, _: &mut Context<'_>, bufs: &[IoSlice<'_>])
498498
-> Poll<Result<usize>>
499499
{
500-
Poll::Ready(StdIo::Write::write_vectored(&mut *self, bufs))
500+
Poll::Ready(io::Write::write_vectored(&mut *self, bufs))
501501
}
502502

503503
fn poll_flush(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>> {
504-
Poll::Ready(StdIo::Write::flush(&mut *self))
504+
Poll::Ready(io::Write::flush(&mut *self))
505505
}
506506

507507
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
@@ -510,7 +510,7 @@ mod if_std {
510510
}
511511
}
512512

513-
impl<T: AsMut<[u8]> + Unpin> AsyncWrite for StdIo::Cursor<T> {
513+
impl<T: AsMut<[u8]> + Unpin> AsyncWrite for io::Cursor<T> {
514514
fn poll_write(
515515
mut self: Pin<&mut Self>,
516516
_: &mut Context<'_>,
@@ -520,7 +520,7 @@ mod if_std {
520520
let result = {
521521
let out = (&mut *self).get_mut().as_mut();
522522
let pos = cmp::min(out.len() as u64, position) as usize;
523-
StdIo::Write::write(&mut &mut out[pos..], buf)
523+
io::Write::write(&mut &mut out[pos..], buf)
524524
};
525525
if let Ok(offset) = result {
526526
self.get_mut().set_position(position + offset as u64);
@@ -531,11 +531,11 @@ mod if_std {
531531
fn poll_write_vectored(self: Pin<&mut Self>, _: &mut Context<'_>, bufs: &[IoSlice<'_>])
532532
-> Poll<Result<usize>>
533533
{
534-
Poll::Ready(StdIo::Write::write_vectored(&mut self.get_mut().get_mut().as_mut(), bufs))
534+
Poll::Ready(io::Write::write_vectored(&mut self.get_mut().get_mut().as_mut(), bufs))
535535
}
536536

537537
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>> {
538-
Poll::Ready(StdIo::Write::flush(&mut self.get_mut().get_mut().as_mut()))
538+
Poll::Ready(io::Write::flush(&mut self.get_mut().get_mut().as_mut()))
539539
}
540540

541541
fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
@@ -547,7 +547,7 @@ mod if_std {
547547
delegate_async_write_to_stdio!();
548548
}
549549

550-
impl AsyncWrite for StdIo::Sink {
550+
impl AsyncWrite for io::Sink {
551551
delegate_async_write_to_stdio!();
552552
}
553553

@@ -569,7 +569,6 @@ mod if_std {
569569
deref_async_seek!();
570570
}
571571

572-
573572
impl<P> AsyncSeek for Pin<P>
574573
where
575574
P: DerefMut + Unpin,
@@ -587,12 +586,12 @@ mod if_std {
587586
fn poll_seek(mut self: Pin<&mut Self>, _: &mut Context<'_>, pos: SeekFrom)
588587
-> Poll<Result<u64>>
589588
{
590-
Poll::Ready(StdIo::Seek::seek(&mut *self, pos))
589+
Poll::Ready(io::Seek::seek(&mut *self, pos))
591590
}
592591
}
593592
}
594593

595-
impl<T: AsRef<[u8]> + Unpin> AsyncSeek for StdIo::Cursor<T> {
594+
impl<T: AsRef<[u8]> + Unpin> AsyncSeek for io::Cursor<T> {
596595
delegate_async_seek_to_stdio!();
597596
}
598597

@@ -604,8 +603,8 @@ mod if_std {
604603
Pin::new(&mut **self.get_mut()).poll_fill_buf(cx)
605604
}
606605

607-
fn consume(self: Pin<&mut Self>, amt: usize) {
608-
Pin::new(&mut **self.get_mut()).consume(amt)
606+
fn consume(mut self: Pin<&mut Self>, amt: usize) {
607+
Pin::new(&mut **self).consume(amt)
609608
}
610609
}
611610
}
@@ -639,11 +638,11 @@ mod if_std {
639638
fn poll_fill_buf<'a>(self: Pin<&'a mut Self>, _: &mut Context<'_>)
640639
-> Poll<Result<&'a [u8]>>
641640
{
642-
Poll::Ready(StdIo::BufRead::fill_buf(self.get_mut()))
641+
Poll::Ready(io::BufRead::fill_buf(self.get_mut()))
643642
}
644643

645644
fn consume(self: Pin<&mut Self>, amt: usize) {
646-
StdIo::BufRead::consume(self.get_mut(), amt)
645+
io::BufRead::consume(self.get_mut(), amt)
647646
}
648647
}
649648
}
@@ -652,11 +651,11 @@ mod if_std {
652651
delegate_async_buf_read_to_stdio!();
653652
}
654653

655-
impl AsyncBufRead for StdIo::Empty {
654+
impl AsyncBufRead for io::Empty {
656655
delegate_async_buf_read_to_stdio!();
657656
}
658657

659-
impl<T: AsRef<[u8]> + Unpin> AsyncBufRead for StdIo::Cursor<T> {
658+
impl<T: AsRef<[u8]> + Unpin> AsyncBufRead for io::Cursor<T> {
660659
delegate_async_buf_read_to_stdio!();
661660
}
662661
}

0 commit comments

Comments
 (0)