-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tokio: move I/O helpers to ext traits
Refs: #1203
- Loading branch information
1 parent
6316aa1
commit ee9c591
Showing
13 changed files
with
322 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::io::copy::{copy, Copy}; | ||
use crate::io::read::{read, Read}; | ||
use crate::io::read_exact::{read_exact, ReadExact}; | ||
|
||
use tokio_io::{AsyncRead, AsyncWrite}; | ||
|
||
/// An extension trait which adds utility methods to `AsyncRead` types. | ||
pub trait AsyncReadExt: AsyncRead { | ||
|
||
/// Copy all data from `self` into the provided `AsyncWrite`. | ||
/// | ||
/// The returned future will copy all the bytes read from `reader` into the | ||
/// `writer` specified. This future will only complete once the `reader` | ||
/// has hit EOF and all bytes have been written to and flushed from the | ||
/// `writer` provided. | ||
/// | ||
/// On success the number of bytes is returned and the `reader` and `writer` | ||
/// are consumed. On error the error is returned and the I/O objects are | ||
/// consumed as well. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// unimplemented!(); | ||
/// ``` | ||
fn copy<'a, W>(&'a mut self, dst: &'a mut W) -> Copy<'a, Self, W> | ||
where | ||
Self: Unpin, | ||
W: AsyncWrite + Unpin + ?Sized, | ||
{ | ||
copy(self, dst) | ||
} | ||
|
||
/// Read data into the provided buffer. | ||
/// | ||
/// The returned future will resolve to the number of bytes read once the | ||
/// read operation is completed. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// unimplemented!(); | ||
/// ``` | ||
fn read<'a>(&'a mut self, dst: &'a mut [u8]) -> Read<'a, Self> | ||
where Self: Unpin, | ||
{ | ||
read(self, dst) | ||
} | ||
|
||
/// Read exactly the amount of data needed to fill the provided buffer. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// unimplemented!(); | ||
/// ``` | ||
fn read_exact<'a>(&'a mut self, dst: &'a mut [u8]) -> ReadExact<'a, Self> | ||
where Self: Unpin, | ||
{ | ||
read_exact(self, dst) | ||
} | ||
} | ||
|
||
impl<R: AsyncRead + ?Sized> AsyncReadExt for R {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::io::write::{write, Write}; | ||
|
||
use tokio_io::AsyncWrite; | ||
|
||
/// An extension trait which adds utility methods to `AsyncWrite` types. | ||
pub trait AsyncWriteExt: AsyncWrite { | ||
/// Write the provided data into `self`. | ||
/// | ||
/// The returned future will resolve to the number of bytes written once the | ||
/// write operation is completed. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// unimplemented!(); | ||
/// ```` | ||
fn write<'a>(&'a mut self, src: &'a [u8]) -> Write<'a, Self> | ||
where Self: Unpin, | ||
{ | ||
write(self, src) | ||
} | ||
} | ||
|
||
impl<W: AsyncWrite + ?Sized> AsyncWriteExt for W {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.