mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
parent
60d81bbe10
commit
41ac1ae2bc
@ -232,12 +232,11 @@ cfg_io_util! {
|
|||||||
pub use split::{split, ReadHalf, WriteHalf};
|
pub use split::{split, ReadHalf, WriteHalf};
|
||||||
|
|
||||||
pub(crate) mod seek;
|
pub(crate) mod seek;
|
||||||
pub use self::seek::Seek;
|
|
||||||
|
|
||||||
pub(crate) mod util;
|
pub(crate) mod util;
|
||||||
pub use util::{
|
pub use util::{
|
||||||
copy, duplex, empty, repeat, sink, AsyncBufReadExt, AsyncReadExt, AsyncSeekExt, AsyncWriteExt,
|
copy, duplex, empty, repeat, sink, AsyncBufReadExt, AsyncReadExt, AsyncSeekExt, AsyncWriteExt,
|
||||||
BufReader, BufStream, BufWriter, DuplexStream, Copy, Empty, Lines, Repeat, Sink, Split, Take,
|
BufReader, BufStream, BufWriter, DuplexStream, Empty, Lines, Repeat, Sink, Split, Take,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,26 +5,21 @@ use std::io;
|
|||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
cfg_io_util! {
|
/// A future that asynchronously copies the entire contents of a reader into a
|
||||||
/// A future that asynchronously copies the entire contents of a reader into a
|
/// writer.
|
||||||
/// writer.
|
#[derive(Debug)]
|
||||||
///
|
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
||||||
/// This struct is generally created by calling [`copy`][copy]. Please
|
struct Copy<'a, R: ?Sized, W: ?Sized> {
|
||||||
/// see the documentation of `copy()` for more details.
|
reader: &'a mut R,
|
||||||
///
|
read_done: bool,
|
||||||
/// [copy]: copy()
|
writer: &'a mut W,
|
||||||
#[derive(Debug)]
|
pos: usize,
|
||||||
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
cap: usize,
|
||||||
pub struct Copy<'a, R: ?Sized, W: ?Sized> {
|
amt: u64,
|
||||||
reader: &'a mut R,
|
buf: Box<[u8]>,
|
||||||
read_done: bool,
|
}
|
||||||
writer: &'a mut W,
|
|
||||||
pos: usize,
|
|
||||||
cap: usize,
|
|
||||||
amt: u64,
|
|
||||||
buf: Box<[u8]>,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
cfg_io_util! {
|
||||||
/// Asynchronously copies the entire contents of a reader into a writer.
|
/// Asynchronously copies the entire contents of a reader into a writer.
|
||||||
///
|
///
|
||||||
/// This function returns a future that will continuously read data from
|
/// This function returns a future that will continuously read data from
|
||||||
@ -58,7 +53,7 @@ cfg_io_util! {
|
|||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn copy<'a, R, W>(reader: &'a mut R, writer: &'a mut W) -> Copy<'a, R, W>
|
pub async fn copy<'a, R, W>(reader: &'a mut R, writer: &'a mut W) -> io::Result<u64>
|
||||||
where
|
where
|
||||||
R: AsyncRead + Unpin + ?Sized,
|
R: AsyncRead + Unpin + ?Sized,
|
||||||
W: AsyncWrite + Unpin + ?Sized,
|
W: AsyncWrite + Unpin + ?Sized,
|
||||||
@ -71,7 +66,7 @@ cfg_io_util! {
|
|||||||
pos: 0,
|
pos: 0,
|
||||||
cap: 0,
|
cap: 0,
|
||||||
buf: vec![0; 2048].into_boxed_slice(),
|
buf: vec![0; 2048].into_boxed_slice(),
|
||||||
}
|
}.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,14 +119,3 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn assert_unpin() {
|
|
||||||
use std::marker::PhantomPinned;
|
|
||||||
crate::is_unpin::<Copy<'_, PhantomPinned, PhantomPinned>>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -25,7 +25,7 @@ cfg_io_util! {
|
|||||||
mod chain;
|
mod chain;
|
||||||
|
|
||||||
mod copy;
|
mod copy;
|
||||||
pub use copy::{copy, Copy};
|
pub use copy::copy;
|
||||||
|
|
||||||
mod empty;
|
mod empty;
|
||||||
pub use empty::{empty, Empty};
|
pub use empty::{empty, Empty};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user