summaryrefslogtreecommitdiffstats
path: root/tokio-executor
diff options
context:
space:
mode:
Diffstat (limited to 'tokio-executor')
-rw-r--r--tokio-executor/Cargo.toml8
-rw-r--r--tokio-executor/src/enter.rs11
-rw-r--r--tokio-executor/src/error.rs2
-rw-r--r--tokio-executor/src/executor.rs29
-rw-r--r--tokio-executor/src/global.rs19
-rw-r--r--tokio-executor/src/lib.rs17
-rw-r--r--tokio-executor/src/park.rs7
-rw-r--r--tokio-executor/src/typed.rs24
-rw-r--r--tokio-executor/tests/executor.rs9
9 files changed, 50 insertions, 76 deletions
diff --git a/tokio-executor/Cargo.toml b/tokio-executor/Cargo.toml
index ed341904..5f8ae6a4 100644
--- a/tokio-executor/Cargo.toml
+++ b/tokio-executor/Cargo.toml
@@ -7,8 +7,9 @@ name = "tokio-executor"
# - Cargo.toml
# - README.md
# - Update CHANGELOG.md.
-# - Create "v0.1.x" git tag.
-version = "0.1.7"
+# - Create "v0.2.x" git tag.
+version = "0.2.0"
+edition = "2018"
documentation = "https://docs.rs/tokio-executor/0.1.7/tokio_executor"
repository = "https://github.com/tokio-rs/tokio"
homepage = "https://github.com/tokio-rs/tokio"
@@ -19,10 +20,11 @@ Future execution primitives
"""
keywords = ["futures", "tokio"]
categories = ["concurrency", "asynchronous"]
+publish = false
[dependencies]
crossbeam-utils = "0.6.2"
futures = "0.1.19"
[dev-dependencies]
-tokio = "0.1.18"
+tokio = { version = "0.2.0", path = "../tokio" }
diff --git a/tokio-executor/src/enter.rs b/tokio-executor/src/enter.rs
index 64bfeb34..597d0910 100644
--- a/tokio-executor/src/enter.rs
+++ b/tokio-executor/src/enter.rs
@@ -1,17 +1,16 @@
+use futures::{self, Future};
use std::cell::Cell;
use std::error::Error;
use std::fmt;
use std::prelude::v1::*;
-use futures::{self, Future};
-
thread_local!(static ENTERED: Cell<bool> = Cell::new(false));
/// Represents an executor context.
///
/// For more details, see [`enter` documentation](fn.enter.html)
pub struct Enter {
- on_exit: Vec<Box<Callback>>,
+ on_exit: Vec<Box<dyn Callback>>,
permanent: bool,
}
@@ -22,7 +21,7 @@ pub struct EnterError {
}
impl fmt::Debug for EnterError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("EnterError")
.field("reason", &self.description())
.finish()
@@ -30,7 +29,7 @@ impl fmt::Debug for EnterError {
}
impl fmt::Display for EnterError {
- fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "{}", self.description())
}
}
@@ -94,7 +93,7 @@ impl Enter {
}
impl fmt::Debug for Enter {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Enter").finish()
}
}
diff --git a/tokio-executor/src/error.rs b/tokio-executor/src/error.rs
index 579239f0..bf46bf56 100644
--- a/tokio-executor/src/error.rs
+++ b/tokio-executor/src/error.rs
@@ -38,7 +38,7 @@ impl SpawnError {
}
impl fmt::Display for SpawnError {
- fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "{}", self.description())
}
}
diff --git a/tokio-executor/src/executor.rs b/tokio-executor/src/executor.rs
index 11276d0e..c0b156f0 100644
--- a/tokio-executor/src/executor.rs
+++ b/tokio-executor/src/executor.rs
@@ -1,5 +1,5 @@
+use crate::SpawnError;
use futures::Future;
-use SpawnError;
/// A value that executes futures.
///
@@ -48,17 +48,15 @@ use SpawnError;
/// # Examples
///
/// ```rust
-/// # extern crate futures;
-/// # extern crate tokio_executor;
-/// # use tokio_executor::Executor;
-/// # fn docs(my_executor: &mut Executor) {
+/// use tokio_executor::Executor;
/// use futures::future::lazy;
+///
+/// # fn docs(my_executor: &mut dyn Executor) {
/// my_executor.spawn(Box::new(lazy(|| {
/// println!("running on the executor");
/// Ok(())
/// }))).unwrap();
/// # }
-/// # fn main() {}
/// ```
///
/// [`spawn`]: #tymethod.spawn
@@ -80,21 +78,19 @@ pub trait Executor {
/// # Examples
///
/// ```rust
- /// # extern crate futures;
- /// # extern crate tokio_executor;
- /// # use tokio_executor::Executor;
- /// # fn docs(my_executor: &mut Executor) {
+ /// use tokio_executor::Executor;
/// use futures::future::lazy;
+ ///
+ /// # fn docs(my_executor: &mut dyn Executor) {
/// my_executor.spawn(Box::new(lazy(|| {
/// println!("running on the executor");
/// Ok(())
/// }))).unwrap();
/// # }
- /// # fn main() {}
/// ```
fn spawn(
&mut self,
- future: Box<Future<Item = (), Error = ()> + Send>,
+ future: Box<dyn Future<Item = (), Error = ()> + Send>,
) -> Result<(), SpawnError>;
/// Provides a best effort **hint** to whether or not `spawn` will succeed.
@@ -115,12 +111,10 @@ pub trait Executor {
/// # Examples
///
/// ```rust
- /// # extern crate futures;
- /// # extern crate tokio_executor;
- /// # use tokio_executor::Executor;
- /// # fn docs(my_executor: &mut Executor) {
+ /// use tokio_executor::Executor;
/// use futures::future::lazy;
///
+ /// # fn docs(my_executor: &mut dyn Executor) {
/// if my_executor.status().is_ok() {
/// my_executor.spawn(Box::new(lazy(|| {
/// println!("running on the executor");
@@ -130,7 +124,6 @@ pub trait Executor {
/// println!("the executor is not in a good state");
/// }
/// # }
- /// # fn main() {}
/// ```
fn status(&self) -> Result<(), SpawnError> {
Ok(())
@@ -140,7 +133,7 @@ pub trait Executor {
impl<E: Executor + ?Sized> Executor for Box<E> {
fn spawn(
&mut self,
- future: Box<Future<Item = (), Error = ()> + Send>,
+ future: Box<dyn Future<Item = (), Error = ()> + Send>,
) -> Result<(), SpawnError> {
(**self).spawn(future)
}
diff --git a/tokio-executor/src/global.rs b/tokio-executor/src/global.rs
index 47f7505c..1c4c53ff 100644
--- a/tokio-executor/src/global.rs
+++ b/tokio-executor/src/global.rs
@@ -1,7 +1,5 @@
use super::{Enter, Executor, SpawnError};
-
use futures::{future, Future};
-
use std::cell::Cell;
/// Executes futures on the default executor for the current execution context.
@@ -37,7 +35,7 @@ impl DefaultExecutor {
}
#[inline]
- fn with_current<F: FnOnce(&mut Executor) -> R, R>(f: F) -> Option<R> {
+ fn with_current<F: FnOnce(&mut dyn Executor) -> R, R>(f: F) -> Option<R> {
EXECUTOR.with(
|current_executor| match current_executor.replace(State::Active) {
State::Ready(executor_ptr) => {
@@ -57,7 +55,7 @@ enum State {
// default executor not defined
Empty,
// default executor is defined and ready to be used
- Ready(*mut Executor),
+ Ready(*mut dyn Executor),
// default executor is currently active (used to detect recursive calls)
Active,
}
@@ -72,7 +70,7 @@ thread_local! {
impl super::Executor for DefaultExecutor {
fn spawn(
&mut self,
- future: Box<Future<Item = (), Error = ()> + Send>,
+ future: Box<dyn Future<Item = (), Error = ()> + Send>,
) -> Result<(), SpawnError> {
DefaultExecutor::with_current(|executor| executor.spawn(future))
.unwrap_or_else(|| Err(SpawnError::shutdown()))
@@ -144,19 +142,14 @@ where
///
/// # Examples
///
-/// ```rust
-/// # extern crate futures;
-/// # extern crate tokio_executor;
-/// # use tokio_executor::spawn;
-/// # pub fn dox() {
+/// ```no_run
+/// use tokio_executor::spawn;
/// use futures::future::lazy;
///
/// spawn(lazy(|| {
/// println!("running on the default executor");
/// Ok(())
/// }));
-/// # }
-/// # pub fn main() {}
/// ```
pub fn spawn<T>(future: T)
where
@@ -210,7 +203,7 @@ where
})
}
-unsafe fn hide_lt<'a>(p: *mut (Executor + 'a)) -> *mut (Executor + 'static) {
+unsafe fn hide_lt<'a>(p: *mut (dyn Executor + 'a)) -> *mut (dyn Executor + 'static) {
use std::mem;
mem::transmute(p)
}
diff --git a/tokio-executor/src/lib.rs b/tokio-executor/src/lib.rs
index 5362d0fa..4e2d3282 100644
--- a/tokio-executor/src/lib.rs
+++ b/tokio-executor/src/lib.rs
@@ -1,5 +1,7 @@
-#![deny(missing_docs, missing_debug_implementations, warnings)]
#![doc(html_root_url = "https://docs.rs/tokio-executor/0.1.7")]
+#![deny(missing_docs, missing_debug_implementations, rust_2018_idioms)]
+#![cfg_attr(test, deny(warnings))]
+#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
//! Task execution related traits and utilities.
//!
@@ -51,9 +53,6 @@
//! [`Park`]: park/index.html
//! [`Future::poll`]: https://docs.rs/futures/0.1/futures/future/trait.Future.html#tymethod.poll
-extern crate crossbeam_utils;
-extern crate futures;
-
mod enter;
mod error;
mod executor;
@@ -61,8 +60,8 @@ mod global;
pub mod park;
mod typed;
-pub use enter::{enter, Enter, EnterError};
-pub use error::SpawnError;
-pub use executor::Executor;
-pub use global::{spawn, with_default, DefaultExecutor};
-pub use typed::TypedExecutor;
+pub use crate::enter::{enter, Enter, EnterError};
+pub use crate::error::SpawnError;
+pub use crate::executor::Executor;
+pub use crate::global::{spawn, with_default, DefaultExecutor};
+pub use crate::typed::TypedExecutor;
diff --git a/tokio-executor/src/park.rs b/tokio-executor/src/park.rs
index 073c4fef..b7c4dbf0 100644
--- a/tokio-executor/src/park.rs
+++ b/tokio-executor/src/park.rs
@@ -44,13 +44,12 @@
//! [up]: trait.Unpark.html
//! [mio]: https://docs.rs/mio/0.6/mio/struct.Poll.html
+use crossbeam_utils::sync::{Parker, Unparker};
use std::marker::PhantomData;
use std::rc::Rc;
use std::sync::Arc;
use std::time::Duration;
-use crossbeam_utils::sync::{Parker, Unparker};
-
/// Block the current thread.
///
/// See [module documentation][mod] for more details.
@@ -128,13 +127,13 @@ pub trait Unpark: Sync + Send + 'static {
fn unpark(&self);
}
-impl Unpark for Box<Unpark> {
+impl Unpark for Box<dyn Unpark> {
fn unpark(&self) {
(**self).unpark()
}
}
-impl Unpark for Arc<Unpark> {
+impl Unpark for Arc<dyn Unpark> {
fn unpark(&self) {
(**self).unpark()
}
diff --git a/tokio-executor/src/typed.rs b/tokio-executor/src/typed.rs
index 22edf29d..5fd0f272 100644
--- a/tokio-executor/src/typed.rs
+++ b/tokio-executor/src/typed.rs
@@ -1,4 +1,4 @@
-use SpawnError;
+use crate::SpawnError;
/// A value that spawns futures of a specific type.
///
@@ -21,11 +21,7 @@ use SpawnError;
/// task is spawned.
///
/// ```rust
-/// #[macro_use]
-/// extern crate futures;
-/// extern crate tokio;
-///
-/// use futures::{Future, Stream, Poll};
+/// use futures::{try_ready, Future, Stream, Poll};
/// use tokio::executor::TypedExecutor;
/// use tokio::sync::oneshot;
///
@@ -69,7 +65,6 @@ use SpawnError;
/// Ok(().into())
/// }
/// }
-/// # pub fn main() {}
/// ```
///
/// By doing this, the `drain` fn can accept a stream that is `!Send` as long as
@@ -90,10 +85,8 @@ pub trait TypedExecutor<T> {
/// # Examples
///
/// ```rust
- /// # extern crate futures;
- /// # extern crate tokio_executor;
- /// # use tokio_executor::TypedExecutor;
- /// # use futures::{Future, Poll};
+ /// use tokio_executor::TypedExecutor;
+ /// use futures::{Future, Poll};
/// fn example<T>(my_executor: &mut T)
/// where
/// T: TypedExecutor<MyFuture>,
@@ -112,7 +105,6 @@ pub trait TypedExecutor<T> {
/// Ok(().into())
/// }
/// }
- /// # fn main() {}
/// ```
fn spawn(&mut self, future: T) -> Result<(), SpawnError>;
@@ -134,10 +126,9 @@ pub trait TypedExecutor<T> {
/// # Examples
///
/// ```rust
- /// # extern crate futures;
- /// # extern crate tokio_executor;
- /// # use tokio_executor::TypedExecutor;
- /// # use futures::{Future, Poll};
+ /// use tokio_executor::TypedExecutor;
+ /// use futures::{Future, Poll};
+ ///
/// fn example<T>(my_executor: &mut T)
/// where
/// T: TypedExecutor<MyFuture>,
@@ -160,7 +151,6 @@ pub trait TypedExecutor<T> {
/// Ok(().into())
/// }
/// }
- /// # fn main() {}
/// ```
fn status(&self) -> Result<(), SpawnError> {
Ok(())
diff --git a/tokio-executor/tests/executor.rs b/tokio-executor/tests/executor.rs
index bb020243..c424df50 100644
--- a/tokio-executor/tests/executor.rs
+++ b/tokio-executor/tests/executor.rs
@@ -1,8 +1,7 @@
-extern crate futures;
-extern crate tokio_executor;
+#![deny(warnings, rust_2018_idioms)]
-use futures::{future::lazy, Future};
-use tokio_executor::DefaultExecutor;
+use futures::{self, future::lazy, Future};
+use tokio_executor::{self, DefaultExecutor};
mod out_of_executor_context {
use super::*;
@@ -10,7 +9,7 @@ mod out_of_executor_context {
fn test<F, E>(spawn: F)
where
- F: Fn(Box<Future<Item = (), Error = ()> + Send>) -> Result<(), E>,
+ F: Fn(Box<dyn Future<Item = (), Error = ()> + Send>) -> Result<(), E>,
{
let res = spawn(Box::new(lazy(|| Ok(()))));
assert!(res.is_err());