mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
chore: format code and enable rustfmt CI task (#1212)
This commit is contained in:
+5
-4
@@ -5,10 +5,11 @@ variables:
|
|||||||
nightly: nightly-2019-06-10
|
nightly: nightly-2019-06-10
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# # Check formatting
|
# Check formatting
|
||||||
# - template: ci/azure-rustfmt.yml
|
- template: ci/azure-rustfmt.yml
|
||||||
# parameters:
|
parameters:
|
||||||
# name: rustfmt
|
rust: $(nightly)
|
||||||
|
name: rustfmt
|
||||||
|
|
||||||
# Test top level crate
|
# Test top level crate
|
||||||
- template: ci/azure-test-stable.yml
|
- template: ci/azure-test-stable.yml
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- template: azure-install-rust.yml
|
- template: azure-install-rust.yml
|
||||||
parameters:
|
parameters:
|
||||||
rust_version: stable
|
rust_version: ${{ parameters.rust }}
|
||||||
- script: |
|
- script: |
|
||||||
rustup component add rustfmt
|
rustup component add rustfmt
|
||||||
cargo fmt --version
|
cargo fmt --version
|
||||||
|
|||||||
@@ -119,8 +119,7 @@ pub trait AsyncWrite {
|
|||||||
///
|
///
|
||||||
/// This function will panic if not called within the context of a future's
|
/// This function will panic if not called within the context of a future's
|
||||||
/// task.
|
/// task.
|
||||||
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>)
|
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>>;
|
||||||
-> Poll<Result<(), io::Error>>;
|
|
||||||
|
|
||||||
/// Write a `Buf` into this value, returning how many bytes were written.
|
/// Write a `Buf` into this value, returning how many bytes were written.
|
||||||
///
|
///
|
||||||
@@ -175,9 +174,11 @@ where
|
|||||||
P: DerefMut + Unpin,
|
P: DerefMut + Unpin,
|
||||||
P::Target: AsyncWrite,
|
P::Target: AsyncWrite,
|
||||||
{
|
{
|
||||||
fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8])
|
fn poll_write(
|
||||||
-> Poll<io::Result<usize>>
|
self: Pin<&mut Self>,
|
||||||
{
|
cx: &mut Context<'_>,
|
||||||
|
buf: &[u8],
|
||||||
|
) -> Poll<io::Result<usize>> {
|
||||||
self.get_mut().as_mut().poll_write(cx, buf)
|
self.get_mut().as_mut().poll_write(cx, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use tokio_io::AsyncRead;
|
use tokio_io::AsyncRead;
|
||||||
use tokio_test::{assert_ready_ok, assert_ready_err};
|
|
||||||
use tokio_test::task::MockTask;
|
use tokio_test::task::MockTask;
|
||||||
|
use tokio_test::{assert_ready_err, assert_ready_ok};
|
||||||
|
|
||||||
use bytes::{BufMut, BytesMut};
|
use bytes::{BufMut, BytesMut};
|
||||||
use pin_utils::pin_mut;
|
use pin_utils::pin_mut;
|
||||||
@@ -22,8 +22,8 @@ fn read_buf_success() {
|
|||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
buf: &mut [u8]) -> Poll<io::Result<usize>>
|
buf: &mut [u8],
|
||||||
{
|
) -> Poll<io::Result<usize>> {
|
||||||
buf[0..11].copy_from_slice(b"hello world");
|
buf[0..11].copy_from_slice(b"hello world");
|
||||||
Poll::Ready(Ok(11))
|
Poll::Ready(Ok(11))
|
||||||
}
|
}
|
||||||
@@ -51,8 +51,8 @@ fn read_buf_error() {
|
|||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
_buf: &mut [u8]) -> Poll<io::Result<usize>>
|
_buf: &mut [u8],
|
||||||
{
|
) -> Poll<io::Result<usize>> {
|
||||||
let err = io::ErrorKind::Other.into();
|
let err = io::ErrorKind::Other.into();
|
||||||
Poll::Ready(Err(err))
|
Poll::Ready(Err(err))
|
||||||
}
|
}
|
||||||
@@ -78,8 +78,8 @@ fn read_buf_no_capacity() {
|
|||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
_buf: &mut [u8]) -> Poll<io::Result<usize>>
|
_buf: &mut [u8],
|
||||||
{
|
) -> Poll<io::Result<usize>> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,8 +107,8 @@ fn read_buf_no_uninitialized() {
|
|||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
buf: &mut [u8]) -> Poll<io::Result<usize>>
|
buf: &mut [u8],
|
||||||
{
|
) -> Poll<io::Result<usize>> {
|
||||||
for b in buf {
|
for b in buf {
|
||||||
assert_eq!(0, *b);
|
assert_eq!(0, *b);
|
||||||
}
|
}
|
||||||
@@ -141,8 +141,8 @@ fn read_buf_uninitialized_ok() {
|
|||||||
fn poll_read(
|
fn poll_read(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
buf: &mut [u8]) -> Poll<io::Result<usize>>
|
buf: &mut [u8],
|
||||||
{
|
) -> Poll<io::Result<usize>> {
|
||||||
assert_eq!(buf[0..11], b"hello world"[..]);
|
assert_eq!(buf[0..11], b"hello world"[..]);
|
||||||
Poll::Ready(Ok(0))
|
Poll::Ready(Ok(0))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,12 +200,10 @@ impl<T> async_sink::Sink<T> for Sender<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start_send(mut self: Pin<&mut Self>, msg: T) -> Result<(), Self::Error> {
|
fn start_send(mut self: Pin<&mut Self>, msg: T) -> Result<(), Self::Error> {
|
||||||
self.as_mut()
|
self.as_mut().try_send(msg).map_err(|err| {
|
||||||
.try_send(msg)
|
assert!(err.is_full(), "call `poll_ready` before sending");
|
||||||
.map_err(|err| {
|
SendError(())
|
||||||
assert!(err.is_full(), "call `poll_ready` before sending");
|
})
|
||||||
SendError(())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
|
|||||||
@@ -98,7 +98,10 @@ impl TcpListener {
|
|||||||
/// }
|
/// }
|
||||||
/// # Ok::<_, Box<dyn std::error::Error>>(())
|
/// # Ok::<_, Box<dyn std::error::Error>>(())
|
||||||
/// ```
|
/// ```
|
||||||
pub fn poll_accept(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<(TcpStream, SocketAddr)>> {
|
pub fn poll_accept(
|
||||||
|
&mut self,
|
||||||
|
cx: &mut Context<'_>,
|
||||||
|
) -> Poll<io::Result<(TcpStream, SocketAddr)>> {
|
||||||
let (io, addr) = ready!(self.poll_accept_std(cx))?;
|
let (io, addr) = ready!(self.poll_accept_std(cx))?;
|
||||||
|
|
||||||
let io = mio::net::TcpStream::from_stream(io)?;
|
let io = mio::net::TcpStream::from_stream(io)?;
|
||||||
@@ -143,7 +146,10 @@ impl TcpListener {
|
|||||||
/// }
|
/// }
|
||||||
/// # Ok::<_, Box<dyn std::error::Error>>(())
|
/// # Ok::<_, Box<dyn std::error::Error>>(())
|
||||||
/// ```
|
/// ```
|
||||||
pub fn poll_accept_std(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<(net::TcpStream, SocketAddr)>> {
|
pub fn poll_accept_std(
|
||||||
|
&mut self,
|
||||||
|
cx: &mut Context<'_>,
|
||||||
|
) -> Poll<io::Result<(net::TcpStream, SocketAddr)>> {
|
||||||
ready!(self.io.poll_read_ready(cx, mio::Ready::readable()))?;
|
ready!(self.io.poll_read_ready(cx, mio::Ready::readable()))?;
|
||||||
|
|
||||||
match self.io.get_ref().accept_std() {
|
match self.io.get_ref().accept_std() {
|
||||||
|
|||||||
+25
-5
@@ -193,7 +193,11 @@ impl TcpStream {
|
|||||||
/// });
|
/// });
|
||||||
/// # Ok::<_, Box<dyn std::error::Error>>(())
|
/// # Ok::<_, Box<dyn std::error::Error>>(())
|
||||||
/// ```
|
/// ```
|
||||||
pub fn poll_read_ready(&self, cx: &mut Context<'_>, mask: mio::Ready) -> Poll<io::Result<mio::Ready>> {
|
pub fn poll_read_ready(
|
||||||
|
&self,
|
||||||
|
cx: &mut Context<'_>,
|
||||||
|
mask: mio::Ready,
|
||||||
|
) -> Poll<io::Result<mio::Ready>> {
|
||||||
self.io.poll_read_ready(cx, mask)
|
self.io.poll_read_ready(cx, mask)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -729,11 +733,19 @@ impl AsyncRead for TcpStream {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
|
fn poll_read(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
cx: &mut Context<'_>,
|
||||||
|
buf: &mut [u8],
|
||||||
|
) -> Poll<io::Result<usize>> {
|
||||||
Pin::new(&mut self.io).poll_read(cx, buf)
|
Pin::new(&mut self.io).poll_read(cx, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_read_buf<B: BufMut>(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut B) -> Poll<io::Result<usize>> {
|
fn poll_read_buf<B: BufMut>(
|
||||||
|
self: Pin<&mut Self>,
|
||||||
|
cx: &mut Context<'_>,
|
||||||
|
buf: &mut B,
|
||||||
|
) -> Poll<io::Result<usize>> {
|
||||||
ready!(self.io.poll_read_ready(cx, mio::Ready::readable()))?;
|
ready!(self.io.poll_read_ready(cx, mio::Ready::readable()))?;
|
||||||
|
|
||||||
let r = unsafe {
|
let r = unsafe {
|
||||||
@@ -795,7 +807,11 @@ impl AsyncRead for TcpStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncWrite for TcpStream {
|
impl AsyncWrite for TcpStream {
|
||||||
fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<io::Result<usize>> {
|
fn poll_write(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
cx: &mut Context<'_>,
|
||||||
|
buf: &[u8],
|
||||||
|
) -> Poll<io::Result<usize>> {
|
||||||
Pin::new(&mut self.io).poll_write(cx, buf)
|
Pin::new(&mut self.io).poll_write(cx, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -809,7 +825,11 @@ impl AsyncWrite for TcpStream {
|
|||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_write_buf<B: Buf>(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut B) -> Poll<io::Result<usize>> {
|
fn poll_write_buf<B: Buf>(
|
||||||
|
self: Pin<&mut Self>,
|
||||||
|
cx: &mut Context<'_>,
|
||||||
|
buf: &mut B,
|
||||||
|
) -> Poll<io::Result<usize>> {
|
||||||
ready!(self.io.poll_write_ready(cx))?;
|
ready!(self.io.poll_write_ready(cx))?;
|
||||||
|
|
||||||
let r = {
|
let r = {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#![cfg(feature = "broken")]
|
#![cfg(feature = "broken")]
|
||||||
#![deny(warnings, rust_2018_idioms)]
|
#![deny(warnings, rust_2018_idioms)]
|
||||||
|
|
||||||
use tokio_macros::{assert_ready, assert_not_ready, assert_ready_eq};
|
|
||||||
use futures::{future, Async, Future, Poll};
|
use futures::{future, Async, Future, Poll};
|
||||||
|
use tokio_macros::{assert_not_ready, assert_ready, assert_ready_eq};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn assert_ready() {
|
fn assert_ready() {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use crate::timer::{HandlePriv, Registration};
|
use crate::timer::{HandlePriv, Registration};
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
use std::task::{self, Poll};
|
use std::task::{self, Poll};
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
/// A future that completes at a specified instant in time.
|
/// A future that completes at a specified instant in time.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -32,12 +32,12 @@
|
|||||||
//! [`Timer`]: timer/struct.Timer.html
|
//! [`Timer`]: timer/struct.Timer.html
|
||||||
|
|
||||||
macro_rules! ready {
|
macro_rules! ready {
|
||||||
($e:expr) => (
|
($e:expr) => {
|
||||||
match $e {
|
match $e {
|
||||||
::std::task::Poll::Ready(v) => v,
|
::std::task::Poll::Ready(v) => v,
|
||||||
::std::task::Poll::Pending => return ::std::task::Poll::Pending,
|
::std::task::Poll::Pending => return ::std::task::Poll::Pending,
|
||||||
}
|
}
|
||||||
)
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod clock;
|
pub mod clock;
|
||||||
|
|||||||
@@ -67,7 +67,10 @@ impl<T: Stream> Stream for Throttle<T> {
|
|||||||
self.as_mut().get_unchecked_mut().has_delayed = true;
|
self.as_mut().get_unchecked_mut().has_delayed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = ready!(self.as_mut().map_unchecked_mut(|me| &mut me.stream).poll_next(cx));
|
let value = ready!(self
|
||||||
|
.as_mut()
|
||||||
|
.map_unchecked_mut(|me| &mut me.stream)
|
||||||
|
.poll_next(cx));
|
||||||
|
|
||||||
if value.is_some() {
|
if value.is_some() {
|
||||||
self.as_mut().get_unchecked_mut().delay.reset_timeout();
|
self.as_mut().get_unchecked_mut().delay.reset_timeout();
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ pub struct Timeout<T> {
|
|||||||
delay: Delay,
|
delay: Delay,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Error returned by `Timeout`.
|
/// Error returned by `Timeout`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Elapsed(());
|
pub struct Elapsed(());
|
||||||
@@ -170,7 +169,7 @@ where
|
|||||||
unsafe {
|
unsafe {
|
||||||
match self.map_unchecked_mut(|me| &mut me.delay).poll(cx) {
|
match self.map_unchecked_mut(|me| &mut me.delay).poll(cx) {
|
||||||
Poll::Ready(()) => Poll::Ready(Err(Elapsed(()))),
|
Poll::Ready(()) => Poll::Ready(Err(Elapsed(()))),
|
||||||
Poll::Pending => Poll::Pending
|
Poll::Pending => Poll::Pending,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -290,7 +290,6 @@ impl Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {
|
pub fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {
|
||||||
|
|
||||||
let mut curr = self.state.load(SeqCst);
|
let mut curr = self.state.load(SeqCst);
|
||||||
|
|
||||||
if is_elapsed(curr) {
|
if is_elapsed(curr) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::{Delay, Error, /*Interval,*/ Timeout};
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::time::{/*Duration,*/ Instant};
|
use std::time::Instant;
|
||||||
use tokio_executor::Enter;
|
use tokio_executor::Enter;
|
||||||
|
|
||||||
/// Handle to timer instance.
|
/// Handle to timer instance.
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ use tokio_io::{AsyncRead, AsyncWrite};
|
|||||||
|
|
||||||
/// An extension trait which adds utility methods to `AsyncRead` types.
|
/// An extension trait which adds utility methods to `AsyncRead` types.
|
||||||
pub trait AsyncReadExt: AsyncRead {
|
pub trait AsyncReadExt: AsyncRead {
|
||||||
|
|
||||||
/// Copy all data from `self` into the provided `AsyncWrite`.
|
/// Copy all data from `self` into the provided `AsyncWrite`.
|
||||||
///
|
///
|
||||||
/// The returned future will copy all the bytes read from `reader` into the
|
/// The returned future will copy all the bytes read from `reader` into the
|
||||||
@@ -24,9 +23,9 @@ pub trait AsyncReadExt: AsyncRead {
|
|||||||
/// unimplemented!();
|
/// unimplemented!();
|
||||||
/// ```
|
/// ```
|
||||||
fn copy<'a, W>(&'a mut self, dst: &'a mut W) -> Copy<'a, Self, W>
|
fn copy<'a, W>(&'a mut self, dst: &'a mut W) -> Copy<'a, Self, W>
|
||||||
where
|
where
|
||||||
Self: Unpin,
|
Self: Unpin,
|
||||||
W: AsyncWrite + Unpin + ?Sized,
|
W: AsyncWrite + Unpin + ?Sized,
|
||||||
{
|
{
|
||||||
copy(self, dst)
|
copy(self, dst)
|
||||||
}
|
}
|
||||||
@@ -42,7 +41,8 @@ pub trait AsyncReadExt: AsyncRead {
|
|||||||
/// unimplemented!();
|
/// unimplemented!();
|
||||||
/// ```
|
/// ```
|
||||||
fn read<'a>(&'a mut self, dst: &'a mut [u8]) -> Read<'a, Self>
|
fn read<'a>(&'a mut self, dst: &'a mut [u8]) -> Read<'a, Self>
|
||||||
where Self: Unpin,
|
where
|
||||||
|
Self: Unpin,
|
||||||
{
|
{
|
||||||
read(self, dst)
|
read(self, dst)
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,8 @@ pub trait AsyncReadExt: AsyncRead {
|
|||||||
/// unimplemented!();
|
/// unimplemented!();
|
||||||
/// ```
|
/// ```
|
||||||
fn read_exact<'a>(&'a mut self, dst: &'a mut [u8]) -> ReadExact<'a, Self>
|
fn read_exact<'a>(&'a mut self, dst: &'a mut [u8]) -> ReadExact<'a, Self>
|
||||||
where Self: Unpin,
|
where
|
||||||
|
Self: Unpin,
|
||||||
{
|
{
|
||||||
read_exact(self, dst)
|
read_exact(self, dst)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ pub trait AsyncWriteExt: AsyncWrite {
|
|||||||
/// unimplemented!();
|
/// unimplemented!();
|
||||||
/// ````
|
/// ````
|
||||||
fn write<'a>(&'a mut self, src: &'a [u8]) -> Write<'a, Self>
|
fn write<'a>(&'a mut self, src: &'a [u8]) -> Write<'a, Self>
|
||||||
where Self: Unpin,
|
where
|
||||||
|
Self: Unpin,
|
||||||
{
|
{
|
||||||
write(self, src)
|
write(self, src)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -40,8 +40,8 @@ mod async_read_ext;
|
|||||||
mod async_write_ext;
|
mod async_write_ext;
|
||||||
mod copy;
|
mod copy;
|
||||||
mod read;
|
mod read;
|
||||||
mod write;
|
|
||||||
mod read_exact;
|
mod read_exact;
|
||||||
|
mod write;
|
||||||
|
|
||||||
pub use self::async_read_ext::AsyncReadExt;
|
pub use self::async_read_ext::AsyncReadExt;
|
||||||
pub use self::async_write_ext::AsyncWriteExt;
|
pub use self::async_write_ext::AsyncWriteExt;
|
||||||
|
|||||||
@@ -11,11 +11,15 @@ use tokio_io::AsyncRead;
|
|||||||
/// Created by the [`read_exact`] function.
|
/// Created by the [`read_exact`] function.
|
||||||
///
|
///
|
||||||
/// [`read_exact`]: fn.read_exact.html
|
/// [`read_exact`]: fn.read_exact.html
|
||||||
pub(crate) fn read_exact<'a, A>(reader: &'a mut A, buf: &'a mut[u8]) -> ReadExact<'a, A>
|
pub(crate) fn read_exact<'a, A>(reader: &'a mut A, buf: &'a mut [u8]) -> ReadExact<'a, A>
|
||||||
where
|
where
|
||||||
A: AsyncRead + Unpin + ?Sized
|
A: AsyncRead + Unpin + ?Sized,
|
||||||
{
|
{
|
||||||
ReadExact { reader, buf, pos: 0 }
|
ReadExact {
|
||||||
|
reader,
|
||||||
|
buf,
|
||||||
|
pos: 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a future which will read exactly enough bytes to fill `buf`,
|
/// Creates a future which will read exactly enough bytes to fill `buf`,
|
||||||
@@ -29,7 +33,6 @@ pub struct ReadExact<'a, A: ?Sized> {
|
|||||||
pos: usize,
|
pos: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn eof() -> io::Error {
|
fn eof() -> io::Error {
|
||||||
io::Error::new(io::ErrorKind::UnexpectedEof, "early eof")
|
io::Error::new(io::ErrorKind::UnexpectedEof, "early eof")
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ pub mod udp {
|
|||||||
//! [`Send`]: struct.Send.html
|
//! [`Send`]: struct.Send.html
|
||||||
//! [`RecvFrom`]: struct.RecvFrom.html
|
//! [`RecvFrom`]: struct.RecvFrom.html
|
||||||
//! [`SendTo`]: struct.SendTo.html
|
//! [`SendTo`]: struct.SendTo.html
|
||||||
pub use tokio_udp::{UdpSocket, Recv, Send, RecvFrom, SendTo};
|
pub use tokio_udp::{Recv, RecvFrom, Send, SendTo, UdpSocket};
|
||||||
}
|
}
|
||||||
#[cfg(feature = "udp")]
|
#[cfg(feature = "udp")]
|
||||||
pub use self::udp::UdpSocket;
|
pub use self::udp::UdpSocket;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![deny(warnings, rust_2018_idioms)]
|
#![deny(warnings, rust_2018_idioms)]
|
||||||
#![feature(async_await)]
|
#![feature(async_await)]
|
||||||
|
|
||||||
use tokio::io::{AsyncRead, AsyncWrite, AsyncReadExt};
|
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite};
|
||||||
use tokio_test::assert_ok;
|
use tokio_test::assert_ok;
|
||||||
|
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ async fn read() {
|
|||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
) -> Poll<io::Result<usize>> {
|
) -> Poll<io::Result<usize>> {
|
||||||
assert_eq!(0, self.poll_cnt);
|
assert_eq!(0, self.poll_cnt);
|
||||||
self.poll_cnt +=1 ;
|
self.poll_cnt += 1;
|
||||||
|
|
||||||
buf[0..11].copy_from_slice(b"hello world");
|
buf[0..11].copy_from_slice(b"hello world");
|
||||||
Poll::Ready(Ok(11))
|
Poll::Ready(Ok(11))
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ async fn read_exact() {
|
|||||||
fn poll_read(
|
fn poll_read(
|
||||||
mut self: Pin<&mut Self>,
|
mut self: Pin<&mut Self>,
|
||||||
_cx: &mut Context<'_>,
|
_cx: &mut Context<'_>,
|
||||||
buf: &mut [u8]
|
buf: &mut [u8],
|
||||||
) -> Poll<io::Result<usize>> {
|
) -> Poll<io::Result<usize>> {
|
||||||
let me = &mut *self;
|
let me = &mut *self;
|
||||||
let len = buf.len();
|
let len = buf.len();
|
||||||
@@ -29,7 +29,9 @@ async fn read_exact() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = Box::new([0; 8]);
|
let mut buf = Box::new([0; 8]);
|
||||||
let mut rd = Rd { val: b"hello world" };
|
let mut rd = Rd {
|
||||||
|
val: b"hello world",
|
||||||
|
};
|
||||||
|
|
||||||
let n = assert_ok!(rd.read_exact(&mut buf[..]).await);
|
let n = assert_ok!(rd.read_exact(&mut buf[..]).await);
|
||||||
assert_eq!(n, 8);
|
assert_eq!(n, 8);
|
||||||
|
|||||||
Reference in New Issue
Block a user