Update Tokio to Rust 2018 (#1082)

This commit is contained in:
Carl Lerche
2019-05-14 10:27:36 -07:00
committed by GitHub
parent 79d8820050
commit cb4aea394e
343 changed files with 1725 additions and 2813 deletions
+5 -7
View File
@@ -1,12 +1,10 @@
use clock::Now;
use timer;
use tokio_executor::Enter;
use crate::clock::Now;
use crate::timer;
use std::cell::Cell;
use std::fmt;
use std::sync::Arc;
use std::time::Instant;
use tokio_executor::Enter;
/// A handle to a source of time.
///
@@ -17,7 +15,7 @@ use std::time::Instant;
/// [`Instant::now`]: https://doc.rust-lang.org/std/time/struct.Instant.html#method.now
#[derive(Default, Clone)]
pub struct Clock {
now: Option<Arc<Now>>,
now: Option<Arc<dyn Now>>,
}
thread_local! {
@@ -92,7 +90,7 @@ impl timer::Now for Clock {
}
impl fmt::Debug for Clock {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Clock")
.field("now", {
if self.now.is_some() {
+5 -7
View File
@@ -1,9 +1,7 @@
#![allow(deprecated)]
use Delay;
use crate::Delay;
use futures::{Async, Future, Poll};
use std::error;
use std::fmt;
use std::time::Instant;
@@ -31,7 +29,7 @@ enum Kind<T> {
Elapsed,
/// Timer returned an error.
Timer(::Error),
Timer(crate::Error),
}
impl<T> Deadline<T> {
@@ -128,7 +126,7 @@ impl<T> DeadlineError<T> {
/// Creates a new `DeadlineError` representing an error encountered by the
/// timer implementation
pub fn timer(err: ::Error) -> DeadlineError<T> {
pub fn timer(err: crate::Error) -> DeadlineError<T> {
DeadlineError(Kind::Timer(err))
}
@@ -141,7 +139,7 @@ impl<T> DeadlineError<T> {
}
/// Consumes `self`, returning the error raised by the timer implementation.
pub fn into_timer(self) -> Option<::Error> {
pub fn into_timer(self) -> Option<crate::Error> {
match self.0 {
Kind::Timer(err) => Some(err),
_ => None,
@@ -162,7 +160,7 @@ impl<T: error::Error> error::Error for DeadlineError<T> {
}
impl<T: fmt::Display> fmt::Display for DeadlineError<T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
use self::Kind::*;
match self.0 {
+2 -4
View File
@@ -1,8 +1,6 @@
use timer::{HandlePriv, Registration};
use Error;
use crate::timer::{HandlePriv, Registration};
use crate::Error;
use futures::{Future, Poll};
use std::time::{Duration, Instant};
/// A future that completes at a specified instant in time.
+21 -40
View File
@@ -4,14 +4,12 @@
//!
//! [`DelayQueue`]: struct.DelayQueue.html
use clock::now;
use timer::Handle;
use wheel::{self, Wheel};
use {Delay, Error};
use futures::{Future, Poll, Stream};
use crate::clock::now;
use crate::timer::Handle;
use crate::wheel::{self, Wheel};
use crate::{Delay, Error};
use futures::{try_ready, Future, Poll, Stream};
use slab::Slab;
use std::cmp;
use std::marker::PhantomData;
use std::time::{Duration, Instant};
@@ -67,16 +65,13 @@ use std::time::{Duration, Instant};
///
/// Using `DelayQueue` to manage cache entries.
///
/// ```rust
/// #[macro_use]
/// extern crate futures;
/// extern crate tokio;
/// # type CacheKey = String;
/// # type Value = String;
/// ```rust,no_run
/// use tokio::timer::{delay_queue, DelayQueue, Error};
/// use futures::{Async, Poll, Stream};
/// use futures::{try_ready, Async, Poll, Stream};
/// use std::collections::HashMap;
/// use std::time::Duration;
/// # type CacheKey = String;
/// # type Value = String;
///
/// struct Cache {
/// entries: HashMap<CacheKey, (Value, delay_queue::Key)>,
@@ -112,7 +107,6 @@ use std::time::{Duration, Instant};
/// Ok(Async::Ready(()))
/// }
/// }
/// # fn main() {}
/// ```
///
/// [`insert`]: #method.insert
@@ -301,11 +295,9 @@ impl<T> DelayQueue<T> {
/// Basic usage
///
/// ```rust
/// # extern crate tokio;
/// use tokio::timer::DelayQueue;
/// use std::time::{Instant, Duration};
///
/// # fn main() {
/// let mut delay_queue = DelayQueue::new();
/// let key = delay_queue.insert_at(
/// "foo", Instant::now() + Duration::from_secs(5));
@@ -313,7 +305,6 @@ impl<T> DelayQueue<T> {
/// // Remove the entry
/// let item = delay_queue.remove(&key);
/// assert_eq!(*item.get_ref(), "foo");
/// # }
/// ```
///
/// [`poll`]: #method.poll
@@ -382,18 +373,15 @@ impl<T> DelayQueue<T> {
/// Basic usage
///
/// ```rust
/// # extern crate tokio;
/// use tokio::timer::DelayQueue;
/// use std::time::Duration;
///
/// # fn main() {
/// let mut delay_queue = DelayQueue::new();
/// let key = delay_queue.insert("foo", Duration::from_secs(5));
///
/// // Remove the entry
/// let item = delay_queue.remove(&key);
/// assert_eq!(*item.get_ref(), "foo");
/// # }
/// ```
///
/// [`poll`]: #method.poll
@@ -435,21 +423,18 @@ impl<T> DelayQueue<T> {
/// Basic usage
///
/// ```rust
/// # extern crate tokio;
/// use tokio::timer::DelayQueue;
/// use std::time::Duration;
///
/// # fn main() {
/// let mut delay_queue = DelayQueue::new();
/// let key = delay_queue.insert("foo", Duration::from_secs(5));
///
/// // Remove the entry
/// let item = delay_queue.remove(&key);
/// assert_eq!(*item.get_ref(), "foo");
/// # }
/// ```
pub fn remove(&mut self, key: &Key) -> Expired<T> {
use wheel::Stack;
use crate::wheel::Stack;
// Special case the `expired` queue
if self.slab[key.index].expired {
@@ -486,11 +471,9 @@ impl<T> DelayQueue<T> {
/// Basic usage
///
/// ```rust
/// # extern crate tokio;
/// use tokio::timer::DelayQueue;
/// use std::time::{Duration, Instant};
///
/// # fn main() {
/// let mut delay_queue = DelayQueue::new();
/// let key = delay_queue.insert("foo", Duration::from_secs(5));
///
@@ -499,7 +482,6 @@ impl<T> DelayQueue<T> {
/// delay_queue.reset_at(&key, Instant::now() + Duration::from_secs(10));
///
/// // "foo"is now scheduled to be returned in 10 seconds
/// # }
/// ```
pub fn reset_at(&mut self, key: &Key, when: Instant) {
self.wheel.remove(&key.index, &mut self.slab);
@@ -543,11 +525,9 @@ impl<T> DelayQueue<T> {
/// Basic usage
///
/// ```rust
/// # extern crate tokio;
/// use tokio::timer::DelayQueue;
/// use std::time::Duration;
///
/// # fn main() {
/// let mut delay_queue = DelayQueue::new();
/// let key = delay_queue.insert("foo", Duration::from_secs(5));
///
@@ -556,7 +536,6 @@ impl<T> DelayQueue<T> {
/// delay_queue.reset(&key, Duration::from_secs(10));
///
/// // "foo"is now scheduled to be returned in 10 seconds
/// # }
/// ```
pub fn reset(&mut self, key: &Key, timeout: Duration) {
self.reset_at(key, now() + timeout);
@@ -573,11 +552,9 @@ impl<T> DelayQueue<T> {
/// # Examples
///
/// ```rust
/// # extern crate tokio;
/// use tokio::timer::DelayQueue;
/// use std::time::Duration;
///
/// # fn main() {
/// let mut delay_queue = DelayQueue::new();
///
/// delay_queue.insert("foo", Duration::from_secs(5));
@@ -587,7 +564,6 @@ impl<T> DelayQueue<T> {
/// delay_queue.clear();
///
/// assert!(delay_queue.is_empty());
/// # }
/// ```
pub fn clear(&mut self) {
self.slab.clear();
@@ -601,7 +577,8 @@ impl<T> DelayQueue<T> {
/// # Examples
///
/// ```rust
/// # use tokio_timer::DelayQueue;
/// use tokio_timer::DelayQueue;
///
/// let delay_queue: DelayQueue<i32> = DelayQueue::with_capacity(10);
/// assert_eq!(delay_queue.capacity(), 10);
/// ```
@@ -629,11 +606,14 @@ impl<T> DelayQueue<T> {
/// # Examples
///
/// ```
/// # use tokio_timer::DelayQueue;
/// # use std::time::Duration;
/// use tokio_timer::DelayQueue;
/// use std::time::Duration;
///
/// let mut delay_queue = DelayQueue::new();
///
/// delay_queue.insert("hello", Duration::from_secs(10));
/// delay_queue.reserve(10);
///
/// assert!(delay_queue.capacity() >= 11);
/// ```
pub fn reserve(&mut self, additional: usize) {
@@ -648,8 +628,9 @@ impl<T> DelayQueue<T> {
/// # Examples
///
/// ```
/// # use tokio_timer::DelayQueue;
/// use tokio_timer::DelayQueue;
/// use std::time::Duration;
///
/// let mut delay_queue = DelayQueue::new();
/// assert!(delay_queue.is_empty());
///
@@ -679,7 +660,7 @@ impl<T> DelayQueue<T> {
try_ready!(delay.poll());
}
let now = ::ms(delay.deadline() - self.start, ::Round::Down);
let now = crate::ms(delay.deadline() - self.start, crate::Round::Down);
self.poll = wheel::Poll::new(now);
}
@@ -702,7 +683,7 @@ impl<T> DelayQueue<T> {
let when = if when < self.start {
0
} else {
::ms(when - self.start, ::Round::Up)
crate::ms(when - self.start, crate::Round::Up)
};
cmp::max(when, self.wheel.elapsed())
+1 -2
View File
@@ -1,5 +1,4 @@
use self::Kind::*;
use std::error;
use std::fmt;
@@ -71,7 +70,7 @@ impl error::Error for Error {
}
impl fmt::Display for Error {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
use std::error::Error;
self.description().fmt(fmt)
}
+4 -7
View File
@@ -1,9 +1,6 @@
use Delay;
use clock;
use futures::{Future, Poll, Stream};
use crate::clock;
use crate::Delay;
use futures::{try_ready, Future, Poll, Stream};
use std::time::{Duration, Instant};
/// A stream representing notifications at fixed interval
@@ -56,7 +53,7 @@ impl Interval {
impl Stream for Interval {
type Item = Instant;
type Error = ::Error;
type Error = crate::Error;
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
// Wait for the delay to be done
+10 -15
View File
@@ -1,5 +1,7 @@
#![doc(html_root_url = "https://docs.rs/tokio-timer/0.2.10")]
#![deny(missing_docs, warnings, missing_debug_implementations)]
#![deny(missing_docs, missing_debug_implementations, rust_2018_idioms)]
#![cfg_attr(test, deny(warnings))]
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
//! Utilities for tracking time.
//!
@@ -29,13 +31,6 @@
//! [`Interval`]: struct.Interval.html
//! [`Timer`]: timer/struct.Timer.html
extern crate tokio_executor;
extern crate crossbeam_utils;
#[macro_use]
extern crate futures;
extern crate slab;
pub mod clock;
pub mod delay_queue;
pub mod throttle;
@@ -52,15 +47,15 @@ mod wheel;
#[deprecated(since = "0.2.6", note = "use Timeout instead")]
#[doc(hidden)]
#[allow(deprecated)]
pub use self::deadline::{Deadline, DeadlineError};
pub use self::delay::Delay;
pub use deadline::{Deadline, DeadlineError};
pub use delay::Delay;
#[doc(inline)]
pub use self::delay_queue::DelayQueue;
pub use self::error::Error;
pub use self::interval::Interval;
pub use delay_queue::DelayQueue;
pub use error::Error;
pub use interval::Interval;
#[doc(inline)]
pub use self::timeout::Timeout;
pub use self::timer::{with_default, Timer};
pub use timeout::Timeout;
pub use timer::{with_default, Timer};
use std::time::{Duration, Instant};
+4 -6
View File
@@ -1,10 +1,8 @@
//! Slow down a stream by enforcing a delay between items.
use {clock, Delay, Error};
use crate::{clock, Delay, Error};
use futures::future::Either;
use futures::{Async, Future, Poll, Stream};
use futures::{try_ready, Async, Future, Poll, Stream};
use std::{
error::Error as StdError,
fmt::{Display, Formatter, Result as FmtResult},
@@ -139,7 +137,7 @@ impl<T> ThrottleError<T> {
}
impl<T: StdError> Display for ThrottleError<T> {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
match self.0 {
Either::A(ref err) => write!(f, "stream error: {}", err),
Either::B(ref err) => write!(f, "timer error: {}", err),
@@ -158,7 +156,7 @@ impl<T: StdError + 'static> StdError for ThrottleError<T> {
// FIXME(taiki-e): When the minimum support version of tokio reaches Rust 1.30,
// replace this with Error::source.
#[allow(deprecated)]
fn cause(&self) -> Option<&StdError> {
fn cause(&self) -> Option<&dyn StdError> {
match self.0 {
Either::A(ref err) => Some(err),
Either::B(ref err) => Some(err),
+6 -16
View File
@@ -4,11 +4,9 @@
//!
//! [`Timeout`]: struct.Timeout.html
use clock::now;
use Delay;
use crate::clock::now;
use crate::Delay;
use futures::{Async, Future, Poll, Stream};
use std::error;
use std::fmt;
use std::time::{Duration, Instant};
@@ -31,8 +29,6 @@ use std::time::{Duration, Instant};
/// example:
///
/// ```rust
/// # extern crate futures;
/// # extern crate tokio;
/// // import the `timeout` function, usually this is done
/// // with `use tokio::prelude::*`
/// use tokio::prelude::FutureExt;
@@ -40,7 +36,6 @@ use std::time::{Duration, Instant};
/// use futures::sync::mpsc;
/// use std::time::Duration;
///
/// # fn main() {
/// let (tx, rx) = mpsc::unbounded();
/// # tx.unbounded_send(()).unwrap();
/// # drop(tx);
@@ -55,7 +50,6 @@ use std::time::{Duration, Instant};
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
/// process.timeout(Duration::from_millis(10))
/// # ).unwrap();
/// # }
/// ```
///
/// # Cancelation
@@ -89,7 +83,7 @@ enum Kind<T> {
Elapsed,
/// Timer returned an error.
Timer(::Error),
Timer(crate::Error),
}
impl<T> Timeout<T> {
@@ -107,14 +101,11 @@ impl<T> Timeout<T> {
/// Create a new `Timeout` set to expire in 10 milliseconds.
///
/// ```rust
/// # extern crate futures;
/// # extern crate tokio;
/// use tokio::timer::Timeout;
/// use futures::Future;
/// use futures::sync::oneshot;
/// use std::time::Duration;
///
/// # fn main() {
/// let (tx, rx) = oneshot::channel();
/// # tx.send(()).unwrap();
///
@@ -122,7 +113,6 @@ impl<T> Timeout<T> {
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
/// Timeout::new(rx, Duration::from_millis(10))
/// # ).unwrap();
/// # }
/// ```
pub fn new(value: T, timeout: Duration) -> Timeout<T> {
let delay = Delay::new_timeout(now() + timeout, timeout);
@@ -265,7 +255,7 @@ impl<T> Error<T> {
/// Creates a new `Error` representing an error encountered by the timer
/// implementation
pub fn timer(err: ::Error) -> Error<T> {
pub fn timer(err: crate::Error) -> Error<T> {
Error(Kind::Timer(err))
}
@@ -278,7 +268,7 @@ impl<T> Error<T> {
}
/// Consumes `self`, returning the error raised by the timer implementation.
pub fn into_timer(self) -> Option<::Error> {
pub fn into_timer(self) -> Option<crate::Error> {
match self.0 {
Kind::Timer(err) => Some(err),
_ => None,
@@ -299,7 +289,7 @@ impl<T: error::Error> error::Error for Error<T> {
}
impl<T: fmt::Display> fmt::Display for Error<T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
use self::Kind::*;
match self.0 {
+1 -2
View File
@@ -1,6 +1,5 @@
use super::Entry;
use Error;
use crate::Error;
use std::ptr;
use std::sync::atomic::AtomicPtr;
use std::sync::atomic::Ordering::SeqCst;
+3 -5
View File
@@ -1,11 +1,9 @@
use atomic::AtomicU64;
use timer::{HandlePriv, Inner};
use Error;
use crate::atomic::AtomicU64;
use crate::timer::{HandlePriv, Inner};
use crate::Error;
use crossbeam_utils::CachePadded;
use futures::task::AtomicTask;
use futures::Poll;
use std::cell::UnsafeCell;
use std::ptr;
use std::sync::atomic::AtomicBool;
+4 -6
View File
@@ -1,12 +1,10 @@
use timer::Inner;
use {Deadline, Delay, Error, Interval, Timeout};
use tokio_executor::Enter;
use crate::timer::Inner;
use crate::{Deadline, Delay, Error, Interval, Timeout};
use std::cell::RefCell;
use std::fmt;
use std::sync::{Arc, Weak};
use std::time::{Duration, Instant};
use tokio_executor::Enter;
/// Handle to timer instance.
///
@@ -190,7 +188,7 @@ impl HandlePriv {
}
impl fmt::Debug for HandlePriv {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "HandlePriv")
}
}
+10 -12
View File
@@ -49,18 +49,16 @@ pub use self::handle::{with_default, Handle};
pub use self::now::{Now, SystemNow};
pub(crate) use self::registration::Registration;
use atomic::AtomicU64;
use wheel;
use Error;
use tokio_executor::park::{Park, ParkThread, Unpark};
use crate::atomic::AtomicU64;
use crate::wheel;
use crate::Error;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::SeqCst;
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::usize;
use std::{cmp, fmt};
use tokio_executor::park::{Park, ParkThread, Unpark};
/// Timer implementation that drives [`Delay`], [`Interval`], and [`Timeout`].
///
@@ -162,7 +160,7 @@ pub(crate) struct Inner {
process: AtomicStack,
/// Unparks the timer thread.
unpark: Box<Unpark>,
unpark: Box<dyn Unpark>,
}
/// Maximum number of timeouts the system can handle concurrently.
@@ -266,7 +264,7 @@ where
/// Run timer related logic
fn process(&mut self) {
let now = ::ms(self.now.now() - self.inner.start, ::Round::Down);
let now = crate::ms(self.now.now() - self.inner.start, crate::Round::Down);
let mut poll = wheel::Poll::new(now);
while let Some(entry) = self.wheel.poll(&mut poll, &mut ()) {
@@ -317,7 +315,7 @@ where
///
/// Returns `None` if the entry was fired.
fn add_entry(&mut self, entry: Arc<Entry>, when: u64) {
use wheel::InsertError;
use crate::wheel::InsertError;
entry.set_when_internal(Some(when));
@@ -426,7 +424,7 @@ impl<T, N> Drop for Timer<T, N> {
// ===== impl Inner =====
impl Inner {
fn new(start: Instant, unpark: Box<Unpark>) -> Inner {
fn new(start: Instant, unpark: Box<dyn Unpark>) -> Inner {
Inner {
num: AtomicUsize::new(0),
elapsed: AtomicU64::new(0),
@@ -479,12 +477,12 @@ impl Inner {
return 0;
}
::ms(deadline - self.start, ::Round::Up)
crate::ms(deadline - self.start, crate::Round::Up)
}
}
impl fmt::Debug for Inner {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Inner").finish()
}
}
+1 -1
View File
@@ -7,4 +7,4 @@ pub trait Now {
fn now(&mut self) -> Instant;
}
pub use clock::Clock as SystemNow;
pub use crate::clock::Clock as SystemNow;
+3 -5
View File
@@ -1,9 +1,7 @@
use clock::now;
use timer::{Entry, HandlePriv};
use Error;
use crate::clock::now;
use crate::timer::{Entry, HandlePriv};
use crate::Error;
use futures::Poll;
use std::sync::Arc;
use std::time::{Duration, Instant};
+1 -2
View File
@@ -1,6 +1,5 @@
use super::Entry;
use wheel;
use crate::wheel;
use std::ptr;
use std::sync::Arc;
+2 -3
View File
@@ -1,5 +1,4 @@
use wheel::Stack;
use crate::wheel::Stack;
use std::fmt;
/// Wheel for a single level in the timer. This wheel contains 64 slots.
@@ -209,7 +208,7 @@ impl<T: Stack> Level<T> {
}
impl<T> fmt::Debug for Level<T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("Level")
.field("occupied", &self.occupied)
.finish()