summaryrefslogtreecommitdiffstats
path: root/tokio-timer
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2019-05-14 10:27:36 -0700
committerGitHub <noreply@github.com>2019-05-14 10:27:36 -0700
commitcb4aea394e6851ae8cc45a68beeaf2c93cc9a0c0 (patch)
tree2158eab230c8717d3b35717e50f14fda6ca0edf1 /tokio-timer
parent79d88200500f6e6c9970e1ad26469276c1a2f71f (diff)
Update Tokio to Rust 2018 (#1082)
Diffstat (limited to 'tokio-timer')
-rw-r--r--tokio-timer/Cargo.toml10
-rw-r--r--tokio-timer/src/clock/clock.rs12
-rw-r--r--tokio-timer/src/deadline.rs12
-rw-r--r--tokio-timer/src/delay.rs6
-rw-r--r--tokio-timer/src/delay_queue.rs61
-rw-r--r--tokio-timer/src/error.rs3
-rw-r--r--tokio-timer/src/interval.rs11
-rw-r--r--tokio-timer/src/lib.rs25
-rw-r--r--tokio-timer/src/throttle.rs10
-rw-r--r--tokio-timer/src/timeout.rs22
-rw-r--r--tokio-timer/src/timer/atomic_stack.rs3
-rw-r--r--tokio-timer/src/timer/entry.rs8
-rw-r--r--tokio-timer/src/timer/handle.rs10
-rw-r--r--tokio-timer/src/timer/mod.rs22
-rw-r--r--tokio-timer/src/timer/now.rs2
-rw-r--r--tokio-timer/src/timer/registration.rs8
-rw-r--r--tokio-timer/src/timer/stack.rs3
-rw-r--r--tokio-timer/src/wheel/level.rs5
-rw-r--r--tokio-timer/tests/clock.rs7
-rw-r--r--tokio-timer/tests/deadline.rs10
-rw-r--r--tokio-timer/tests/delay.rs13
-rw-r--r--tokio-timer/tests/hammer.rs12
-rw-r--r--tokio-timer/tests/interval.rs10
-rw-r--r--tokio-timer/tests/queue.rs13
-rw-r--r--tokio-timer/tests/support/mod.rs4
-rw-r--r--tokio-timer/tests/throttle.rs7
-rw-r--r--tokio-timer/tests/timeout.rs10
27 files changed, 119 insertions, 200 deletions
diff --git a/tokio-timer/Cargo.toml b/tokio-timer/Cargo.toml
index 6d13ac72..eac11d3a 100644
--- a/tokio-timer/Cargo.toml
+++ b/tokio-timer/Cargo.toml
@@ -7,8 +7,9 @@ name = "tokio-timer"
# - Cargo.toml
# - README.md
# - Update CHANGELOG.md.
-# - Create "v0.2.x" git tag.
-version = "0.2.10"
+# - Create "v0.3.x" git tag.
+version = "0.3.0"
+edition = "2018"
authors = ["Carl Lerche <me@carllerche.com>"]
license = "MIT"
readme = "README.md"
@@ -18,10 +19,11 @@ homepage = "https://github.com/tokio-rs/tokio"
description = """
Timer facilities for Tokio
"""
+publish = false
[dependencies]
futures = "0.1.19"
-tokio-executor = "0.1.1"
+tokio-executor = { version = "0.2.0", path = "../tokio-executor" }
crossbeam-utils = "0.6.0"
# Backs `DelayQueue`
@@ -30,4 +32,4 @@ slab = "0.4.1"
[dev-dependencies]
rand = "0.6"
tokio-mock-task = "0.1.0"
-tokio = "0.1.7"
+tokio = { version = "0.2.0", path = "../tokio" }
diff --git a/tokio-timer/src/clock/clock.rs b/tokio-timer/src/clock/clock.rs
index 9b9de89e..a4c4a0f3 100644
--- a/tokio-timer/src/clock/clock.rs
+++ b/tokio-timer/src/clock/clock.rs
@@ -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() {
diff --git a/tokio-timer/src/deadline.rs b/tokio-timer/src/deadline.rs
index c4c19b8b..29f0c827 100644
--- a/tokio-timer/src/deadline.rs
+++ b/tokio-timer/src/deadline.rs
@@ -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 {
diff --git a/tokio-timer/src/delay.rs b/tokio-timer/src/delay.rs
index c48adccd..941dde7a 100644
--- a/tokio-timer/src/delay.rs
+++ b/tokio-timer/src/delay.rs
@@ -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.
diff --git a/tokio-timer/src/delay_queue.rs b/tokio-timer/src/delay_queue.rs
index 1f4b0a17..70190e83 100644
--- a/tokio-timer/src/delay_queue.rs
+++ b/tokio-timer/src/delay_queue.rs
@@ -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())
diff --git a/tokio-timer/src/error.rs b/tokio-timer/src/error.rs
index a6136d8b..968957fa 100644
--- a/tokio-timer/src/error.rs
+++ b/tokio-timer/src/error.rs
@@ -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)
}
diff --git a/tokio-timer/src/interval.rs b/tokio-timer/src/interval.rs
index 019efe6a..e065bf12 100644
--- a/tokio-timer/src/interval.rs
+++ b/tokio-timer/src/interval.rs
@@ -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
diff --git a/tokio-timer/src/lib.rs b/tokio-timer/src/lib.rs
index b1069207..3a960240 100644
--- a/tokio-timer/src/lib.rs
+++ b/tokio-timer/src/lib.rs
@@ -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};
diff --git a/tokio-timer/src/throttle.rs b/tokio-timer/src/throttle.rs
index 0ab49aaa..de71bf7f 100644
--- a/tokio-timer/src/throttle.rs
+++ b/tokio-timer/src/throttle.rs
@@ -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),
diff --git a/tokio-timer/src/timeout.rs b/tokio-timer/src/timeout.rs
index 1c02a686..e860d3f0 100644
--- a/tokio-timer/src/timeout.rs
+++ b/tokio-timer/src/timeout.rs
@@ -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 {
diff --git a/tokio-timer/src/timer/atomic_stack.rs b/tokio-timer/src/timer/atomic_stack.rs
index 4e7d8ed6..bbc540a2 100644
--- a/tokio-timer/src/timer/atomic_stack.rs
+++ b/tokio-timer/src/timer/atomic_stack.rs
@@ -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;
diff --git a/tokio-timer/src/timer/entry.rs b/tokio-timer/src/timer/entry.rs
index 40979afa..3ce969a1 100644
--- a/tokio-timer/src/timer/entry.rs
+++ b/tokio-timer/src/timer/entry.rs
@@ -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;
diff --git a/tokio-timer/src/timer/handle.rs b/tokio-timer/src/timer/handle.rs
index c9598b9a..7e8b95c7 100644
--- a/tokio-timer/src/timer/handle.rs
+++ b/tokio-timer/src/timer/handle.rs
@@ -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")
}
}
diff --git a/tokio-timer/src/timer/mod.rs b/tokio-timer/src/timer/mod.rs
index 05b0672e..6b2d7f83 100644
--- a/tokio-timer/src/timer/mod.rs
+++ b/tokio-timer/src/timer/mod.rs
@@ -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()
}
}
diff --git a/tokio-timer/src/timer/now.rs b/tokio-timer/src/timer/now.rs
index 9f23bad7..53754427 100644
--- a/tokio-timer/src/timer/now.rs
+++ b/tokio-timer/src/timer/now.rs
@@ -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;
diff --git a/tokio-timer/src/timer/registration.rs b/tokio-timer/src/timer/registration.rs
index dad1355d..ee7e3feb 100644
--- a/tokio-timer/src/timer/registration.rs
+++ b/tokio-timer/src/timer/registration.rs
@@ -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};
diff --git a/tokio-timer/src/timer/stack.rs b/tokio-timer/src/timer/stack.rs
index c63eed97..9309b470 100644
--- a/tokio-timer/src/timer/stack.rs
+++ b/tokio-timer/src/timer/stack.rs
@@ -1,6 +1,5 @@
use super::Entry;
-use wheel;
-
+use crate::wheel;
use std::ptr;
use std::sync::Arc;
diff --git a/tokio-timer/src/wheel/level.rs b/tokio-timer/src/wheel/level.rs
index 6bbd128e..868e6a79 100644
--- a/tokio-timer/src/wheel/level.rs
+++ b/tokio-timer/src/wheel/level.rs
@@ -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()
diff --git a/tokio-timer/tests/clock.rs b/tokio-timer/tests/clock.rs
index d8bcaaeb..d75f3d37 100644
--- a/tokio-timer/tests/clock.rs
+++ b/tokio-timer/tests/clock.rs
@@ -1,11 +1,10 @@
-extern crate tokio_executor;
-extern crate tokio_timer;
+#![deny(warnings, rust_2018_idioms)]
+use std::time::Instant;
+use tokio_executor;
use tokio_timer::clock;
use tokio_timer::clock::*;
-use std::time::Instant;
-
struct ConstNow(Instant);
impl Now for ConstNow {
diff --git a/tokio-timer/tests/deadline.rs b/tokio-timer/tests/deadline.rs
index 8eec79ae..712cc5f3 100644
--- a/tokio-timer/tests/deadline.rs
+++ b/tokio-timer/tests/deadline.rs
@@ -1,16 +1,12 @@
+#![deny(warnings, rust_2018_idioms)]
#![allow(deprecated)]
-extern crate futures;
-extern crate tokio_executor;
-extern crate tokio_timer;
-#[macro_use]
mod support;
-use support::*;
-
-use tokio_timer::*;
+use crate::support::*;
use futures::sync::oneshot;
use futures::{future, Future};
+use tokio_timer::*;
#[test]
fn simultaneous_deadline_future_completion() {
diff --git a/tokio-timer/tests/delay.rs b/tokio-timer/tests/delay.rs
index d21106c6..43066260 100644
--- a/tokio-timer/tests/delay.rs
+++ b/tokio-timer/tests/delay.rs
@@ -1,17 +1,12 @@
-extern crate futures;
-extern crate tokio_executor;
-extern crate tokio_timer;
+#![deny(warnings, rust_2018_idioms)]
-#[macro_use]
mod support;
-use support::*;
-
-use tokio_timer::timer::Handle;
-use tokio_timer::*;
+use crate::support::*;
use futures::Future;
-
use std::time::{Duration, Instant};
+use tokio_timer::timer::Handle;
+use tokio_timer::*;