chore: apply rustfmt to all crates (#917)

This commit is contained in:
Carl Lerche
2019-02-21 11:56:15 -08:00
committed by GitHub
parent ab595d0825
commit 80162306e7
253 changed files with 3710 additions and 3407 deletions
+5 -3
View File
@@ -1,4 +1,4 @@
use std::future::{Future as StdFuture};
use std::future::Future as StdFuture;
async fn map_ok<T: StdFuture>(future: T) -> Result<(), ()> {
let _ = await!(future);
@@ -7,7 +7,8 @@ async fn map_ok<T: StdFuture>(future: T) -> Result<(), ()> {
/// Like `tokio::run`, but takes an `async` block
pub fn run_async<F>(future: F)
where F: StdFuture<Output = ()> + Send + 'static,
where
F: StdFuture<Output = ()> + Send + 'static,
{
use tokio_async_await::compat::backward;
let future = backward::Compat::new(map_ok(future));
@@ -17,7 +18,8 @@ where F: StdFuture<Output = ()> + Send + 'static,
/// Like `tokio::spawn`, but takes an `async` block
pub fn spawn_async<F>(future: F)
where F: StdFuture<Output = ()> + Send + 'static,
where
F: StdFuture<Output = ()> + Send + 'static,
{
use tokio_async_await::compat::backward;
let future = backward::Compat::new(map_ok(future));
+38 -33
View File
@@ -355,19 +355,15 @@
//! [`BytesMut`]: https://docs.rs/bytes/0.4/bytes/struct.BytesMut.html
use {
codec::{
Decoder, Encoder, FramedRead, FramedWrite, Framed
},
io::{
AsyncRead, AsyncWrite
},
codec::{Decoder, Encoder, Framed, FramedRead, FramedWrite},
io::{AsyncRead, AsyncWrite},
};
use bytes::{Buf, BufMut, Bytes, BytesMut, IntoBuf};
use std::{cmp, fmt};
use std::error::Error as StdError;
use std::io::{self, Cursor};
use std::{cmp, fmt};
/// Configure length delimited `LengthDelimitedCodec`s.
///
@@ -476,9 +472,10 @@ impl LengthDelimitedCodec {
};
if n > self.builder.max_frame_len as u64 {
return Err(io::Error::new(io::ErrorKind::InvalidData, FrameTooBig {
_priv: (),
}));
return Err(io::Error::new(
io::ErrorKind::InvalidData,
FrameTooBig { _priv: () },
));
}
// The check above ensures there is no overflow
@@ -494,7 +491,12 @@ impl LengthDelimitedCodec {
// Error handling
match n {
Some(n) => n,
None => return Err(io::Error::new(io::ErrorKind::InvalidInput, "provided length would overflow after adjustment")),
None => {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"provided length would overflow after adjustment",
));
}
}
};
@@ -528,15 +530,13 @@ impl Decoder for LengthDelimitedCodec {
fn decode(&mut self, src: &mut BytesMut) -> io::Result<Option<BytesMut>> {
let n = match self.state {
DecodeState::Head => {
match try!(self.decode_head(src)) {
Some(n) => {
self.state = DecodeState::Data(n);
n
}
None => return Ok(None),
DecodeState::Head => match try!(self.decode_head(src)) {
Some(n) => {
self.state = DecodeState::Data(n);
n
}
}
None => return Ok(None),
},
DecodeState::Data(n) => n,
};
@@ -563,9 +563,10 @@ impl Encoder for LengthDelimitedCodec {
let n = (&data).into_buf().remaining();
if n > self.builder.max_frame_len {
return Err(io::Error::new(io::ErrorKind::InvalidInput, FrameTooBig {
_priv: (),
}));
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
FrameTooBig { _priv: () },
));
}
// Adjust `n` with bounds checking
@@ -575,10 +576,12 @@ impl Encoder for LengthDelimitedCodec {
n.checked_sub(self.builder.length_adjustment as usize)
};
let n = n.ok_or_else(|| io::Error::new(
io::ErrorKind::InvalidInput,
"provided length would overflow after adjustment",
))?;
let n = n.ok_or_else(|| {
io::Error::new(
io::ErrorKind::InvalidInput,
"provided length would overflow after adjustment",
)
})?;
// Reserve capacity in the destination buffer to fit the frame and
// length field (plus adjustment).
@@ -892,7 +895,8 @@ impl Builder {
/// # pub fn main() {}
/// ```
pub fn new_read<T>(&self, upstream: T) -> FramedRead<T, LengthDelimitedCodec>
where T: AsyncRead,
where
T: AsyncRead,
{
FramedRead::new(upstream, self.new_codec())
}
@@ -915,7 +919,8 @@ impl Builder {
/// # pub fn main() {}
/// ```
pub fn new_write<T>(&self, inner: T) -> FramedWrite<T, LengthDelimitedCodec>
where T: AsyncWrite,
where
T: AsyncWrite,
{
FramedWrite::new(inner, self.new_codec())
}
@@ -939,7 +944,8 @@ impl Builder {
/// # pub fn main() {}
/// ```
pub fn new_framed<T>(&self, inner: T) -> Framed<T, LengthDelimitedCodec>
where T: AsyncRead + AsyncWrite,
where
T: AsyncRead + AsyncWrite,
{
Framed::new(inner, self.new_codec())
}
@@ -950,17 +956,16 @@ impl Builder {
}
fn get_num_skip(&self) -> usize {
self.num_skip.unwrap_or(self.length_field_offset + self.length_field_len)
self.num_skip
.unwrap_or(self.length_field_offset + self.length_field_len)
}
}
// ===== impl FrameTooBig =====
impl fmt::Debug for FrameTooBig {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("FrameTooBig")
.finish()
f.debug_struct("FrameTooBig").finish()
}
}
+1 -8
View File
@@ -11,14 +11,7 @@
//! [transports]: https://tokio.rs/docs/going-deeper/frames/
pub use tokio_codec::{
Decoder,
Encoder,
Framed,
FramedParts,
FramedRead,
FramedWrite,
BytesCodec,
LinesCodec,
BytesCodec, Decoder, Encoder, Framed, FramedParts, FramedRead, FramedWrite, LinesCodec,
};
pub mod length_delimited;
+4 -2
View File
@@ -7,7 +7,9 @@
//! the context of the Tokio runtime as they require Tokio specific features to
//! function.
pub use tokio_fs::{create_dir, create_dir_all, file, hard_link, metadata, os, read_dir, read_link};
pub use tokio_fs::{remove_dir, remove_file, rename, set_permissions, symlink_metadata, File};
pub use tokio_fs::OpenOptions;
pub use tokio_fs::{
create_dir, create_dir_all, file, hard_link, metadata, os, read_dir, read_link,
};
pub use tokio_fs::{read, write, ReadFile, WriteFile};
pub use tokio_fs::{remove_dir, remove_file, rename, set_permissions, symlink_metadata, File};
+5 -38
View File
@@ -45,51 +45,18 @@
//! [`ErrorKind`]: enum.ErrorKind.html
//! [`Result`]: type.Result.html
pub use tokio_io::{
AsyncRead,
AsyncWrite,
};
pub use tokio_io::{AsyncRead, AsyncWrite};
// standard input, output, and error
#[cfg(feature = "fs")]
pub use tokio_fs::{
stdin,
Stdin,
stdout,
Stdout,
stderr,
Stderr,
};
pub use tokio_fs::{stderr, stdin, stdout, Stderr, Stdin, Stdout};
// Utils
pub use tokio_io::io::{
copy,
Copy,
flush,
Flush,
lines,
Lines,
read,
read_exact,
ReadExact,
read_to_end,
ReadToEnd,
read_until,
ReadUntil,
ReadHalf,
shutdown,
Shutdown,
write_all,
WriteAll,
WriteHalf,
copy, flush, lines, read, read_exact, read_to_end, read_until, shutdown, write_all, Copy,
Flush, Lines, ReadExact, ReadHalf, ReadToEnd, ReadUntil, Shutdown, WriteAll, WriteHalf,
};
// Re-export io::Error so that users don't have to deal
// with conflicts when `use`ing `futures::io` and `std::io`.
pub use ::std::io::{
Error,
ErrorKind,
Result,
Read,
Write,
};
pub use std::io::{Error, ErrorKind, Read, Result, Write};
+12 -13
View File
@@ -1,10 +1,9 @@
#![doc(html_root_url = "https://docs.rs/tokio/0.1.15")]
#![deny(missing_docs, warnings, missing_debug_implementations)]
#![cfg_attr(feature = "async-await-preview", feature(
async_await,
await_macro,
futures_api,
))]
#![cfg_attr(
feature = "async-await-preview",
feature(async_await, await_macro, futures_api,)
)]
//! A runtime for writing reliable, asynchronous, and slim applications.
//!
@@ -88,24 +87,24 @@ extern crate bytes;
extern crate mio;
#[cfg(feature = "rt-full")]
extern crate num_cpus;
#[cfg(feature = "rt-full")]
extern crate tokio_current_thread;
#[cfg(feature = "io")]
extern crate tokio_io;
#[cfg(feature = "codec")]
extern crate tokio_codec;
#[cfg(feature = "rt-full")]
extern crate tokio_current_thread;
#[cfg(feature = "fs")]
extern crate tokio_fs;
#[cfg(feature = "io")]
extern crate tokio_io;
#[cfg(feature = "reactor")]
extern crate tokio_reactor;
#[cfg(feature = "rt-full")]
extern crate tokio_threadpool;
#[cfg(feature = "sync")]
extern crate tokio_sync;
#[cfg(feature = "timer")]
extern crate tokio_timer;
#[cfg(feature = "tcp")]
extern crate tokio_tcp;
#[cfg(feature = "rt-full")]
extern crate tokio_threadpool;
#[cfg(feature = "timer")]
extern crate tokio_timer;
#[cfg(feature = "udp")]
extern crate tokio_udp;
+7 -34
View File
@@ -11,45 +11,18 @@
//! The prelude may grow over time as additional items see ubiquitous use.
#[cfg(feature = "io")]
pub use tokio_io::{
AsyncRead,
AsyncWrite,
};
pub use tokio_io::{AsyncRead, AsyncWrite};
pub use util::{
FutureExt,
StreamExt,
};
pub use util::{FutureExt, StreamExt};
pub use ::std::io::{
Read,
Write,
};
pub use std::io::{Read, Write};
pub use futures::{
Future,
future,
Stream,
stream,
Sink,
IntoFuture,
Async,
AsyncSink,
Poll,
task,
};
pub use futures::{future, stream, task, Async, AsyncSink, Future, IntoFuture, Poll, Sink, Stream};
#[cfg(feature = "async-await-preview")]
#[doc(inline)]
pub use tokio_async_await::{
io::{
AsyncReadExt,
AsyncWriteExt,
},
sink::{
SinkExt,
},
stream::{
StreamExt as StreamAsyncExt,
},
io::{AsyncReadExt, AsyncWriteExt},
sink::SinkExt,
stream::StreamExt as StreamAsyncExt,
};
+1 -6
View File
@@ -136,12 +136,7 @@
//! [`std::io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
pub use tokio_reactor::{
Reactor,
Handle,
Background,
Turn,
Registration,
PollEvented as PollEvented2,
Background, Handle, PollEvented as PollEvented2, Reactor, Registration, Turn,
};
mod poll_evented;
+30 -22
View File
@@ -10,9 +10,9 @@
use std::fmt;
use std::io::{self, Read, Write};
use std::sync::Mutex;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::Relaxed;
use std::sync::Mutex;
use futures::{task, Async, Poll};
use mio::event::Evented;
@@ -41,9 +41,7 @@ struct Inner {
impl<E: fmt::Debug> fmt::Debug for PollEvented<E> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("PollEvented")
.field("io", &self.io)
.finish()
f.debug_struct("PollEvented").field("io", &self.io).finish()
}
}
@@ -51,7 +49,8 @@ impl<E> PollEvented<E> {
/// Creates a new readiness stream associated with the provided
/// `loop_handle` and for the given `source`.
pub fn new(io: E, handle: &Handle) -> io::Result<PollEvented<E>>
where E: Evented,
where
E: Evented,
{
let registration = Registration::new();
registration.register(&io)?;
@@ -153,7 +152,9 @@ impl<E> PollEvented<E> {
};
// Cache the value
self.inner.write_readiness.store(ready2usize(ready), Relaxed);
self.inner
.write_readiness
.store(ready2usize(ready), Relaxed);
().into()
}
@@ -334,17 +335,17 @@ impl<E> PollEvented<E> {
/// method is called, and will likely return an error if this `PollEvented`
/// was created on a separate event loop from the `handle` specified.
pub fn deregister(&self) -> io::Result<()>
where E: Evented,
where
E: Evented,
{
self.inner.registration.lock().unwrap()
.deregister(&self.io)
self.inner.registration.lock().unwrap().deregister(&self.io)
}
}
impl<E: Read> Read for PollEvented<E> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if let Async::NotReady = self.poll_read() {
return Err(io::ErrorKind::WouldBlock.into())
return Err(io::ErrorKind::WouldBlock.into());
}
let r = self.get_mut().read(buf);
@@ -353,14 +354,14 @@ impl<E: Read> Read for PollEvented<E> {
self.need_read()?;
}
return r
return r;
}
}
impl<E: Write> Write for PollEvented<E> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
if let Async::NotReady = self.poll_write() {
return Err(io::ErrorKind::WouldBlock.into())
return Err(io::ErrorKind::WouldBlock.into());
}
let r = self.get_mut().write(buf);
@@ -369,12 +370,12 @@ impl<E: Write> Write for PollEvented<E> {
self.need_write()?;
}
return r
return r;
}
fn flush(&mut self) -> io::Result<()> {
if let Async::NotReady = self.poll_write() {
return Err(io::ErrorKind::WouldBlock.into())
return Err(io::ErrorKind::WouldBlock.into());
}
let r = self.get_mut().flush();
@@ -383,12 +384,11 @@ impl<E: Write> Write for PollEvented<E> {
self.need_write()?;
}
return r
return r;
}
}
impl<E: Read> AsyncRead for PollEvented<E> {
}
impl<E: Read> AsyncRead for PollEvented<E> {}
impl<E: Write> AsyncWrite for PollEvented<E> {
fn shutdown(&mut self) -> Poll<(), io::Error> {
@@ -430,8 +430,8 @@ fn usize2ready(bits: usize) -> Ready {
#[cfg(unix)]
mod platform {
use mio::Ready;
use mio::unix::UnixReady;
use mio::Ready;
const HUP: usize = 1 << 2;
const ERROR: usize = 1 << 3;
@@ -476,14 +476,22 @@ mod platform {
bits
}
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios",
target_os = "macos"))]
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
))]
fn usize2ready_aio(ready: &mut UnixReady) {
ready.insert(UnixReady::aio());
}
#[cfg(not(any(target_os = "dragonfly",
target_os = "freebsd", target_os = "ios", target_os = "macos")))]
#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "macos"
)))]
fn usize2ready_aio(_ready: &mut UnixReady) {
// aio not available here → empty
}
+1 -4
View File
@@ -10,7 +10,4 @@
//! - [mpsc](mpsc/index.html), a multi-producer, single-consumer channel for
//! sending values between tasks.
pub use tokio_sync::{
mpsc,
oneshot,
};
pub use tokio_sync::{mpsc, oneshot};
+1 -9
View File
@@ -82,15 +82,7 @@
//! [Interval]: struct.Interval.html
//! [`DelayQueue`]: struct.DelayQueue.html
pub use tokio_timer::{
delay_queue,
DelayQueue,
Error,
Interval,
Delay,
Timeout,
timeout,
};
pub use tokio_timer::{delay_queue, timeout, Delay, DelayQueue, Error, Interval, Timeout};
#[deprecated(since = "0.1.8", note = "use Timeout instead")]
#[allow(deprecated)]
+7 -3
View File
@@ -1,4 +1,4 @@
use futures::{Async, Poll, Stream, Sink, StartSend};
use futures::{Async, Poll, Sink, StartSend, Stream};
/// A stream combinator which combines the yields the current item
/// plus its count starting from 0.
@@ -13,7 +13,10 @@ pub struct Enumerate<T> {
impl<T> Enumerate<T> {
pub(crate) fn new(stream: T) -> Self {
Self { inner: stream, count: 0 }
Self {
inner: stream,
count: 0,
}
}
/// Acquires a reference to the underlying stream that this combinator is
@@ -61,7 +64,8 @@ where
// Forwarding impl of Sink from the underlying stream
impl<T> Sink for Enumerate<T>
where T: Sink
where
T: Sink,
{
type SinkItem = T::SinkItem;
type SinkError = T::SinkError;
+5 -5
View File
@@ -7,8 +7,7 @@ use tokio_timer::Timeout;
use futures::Future;
#[cfg(feature = "timer")]
use std::time::{Instant, Duration};
use std::time::{Duration, Instant};
/// An extension trait for `Future` that provides a variety of convenient
/// combinator functions.
@@ -24,7 +23,6 @@ use std::time::{Instant, Duration};
///
/// [`timeout`]: #method.timeout
pub trait FutureExt: Future {
/// Creates a new future which allows `self` until `timeout`.
///
/// This combinator creates a new future which wraps the receiving future
@@ -60,7 +58,8 @@ pub trait FutureExt: Future {
/// ```
#[cfg(feature = "timer")]
fn timeout(self, timeout: Duration) -> Timeout<Self>
where Self: Sized,
where
Self: Sized,
{
Timeout::new(self, timeout)
}
@@ -70,7 +69,8 @@ pub trait FutureExt: Future {
#[allow(deprecated)]
#[doc(hidden)]
fn deadline(self, deadline: Instant) -> Deadline<Self>
where Self: Sized,
where
Self: Sized,
{
Deadline::new(self, deadline)
}
+1 -1
View File
@@ -7,9 +7,9 @@
//! [`FutureExt`]: trait.FutureExt.html
//! [`StreamExt`]: trait.StreamExt.html
mod enumerate;
mod future;
mod stream;
mod enumerate;
pub use self::future::FutureExt;
pub use self::stream::StreamExt;
+7 -7
View File
@@ -1,8 +1,5 @@
#[cfg(feature = "timer")]
use tokio_timer::{
throttle::Throttle,
Timeout,
};
use tokio_timer::{throttle::Throttle, Timeout};
use futures::Stream;
@@ -29,7 +26,8 @@ pub trait StreamExt: Stream {
/// Errors are also delayed.
#[cfg(feature = "timer")]
fn throttle(self, duration: Duration) -> Throttle<Self>
where Self: Sized
where
Self: Sized,
{
Throttle::new(self, duration)
}
@@ -47,7 +45,8 @@ pub trait StreamExt: Stream {
/// an iterator with more than [`std::usize::MAX`] elements either produces the
/// wrong result or panics.
fn enumerate(self) -> Enumerate<Self>
where Self: Sized,
where
Self: Sized,
{
Enumerate::new(self)
}
@@ -86,7 +85,8 @@ pub trait StreamExt: Stream {
/// ```
#[cfg(feature = "timer")]
fn timeout(self, timeout: Duration) -> Timeout<Self>
where Self: Sized,
where
Self: Sized,
{
Timeout::new(self, timeout)
}