Reexport other crates into smol

This commit is contained in:
Stjepan Glavina 2020-07-20 19:20:29 +02:00
parent b3005d9420
commit 39f67144a4
23 changed files with 44 additions and 93 deletions

View File

@ -25,10 +25,11 @@ tokio02 = ["tokio"]
[dependencies]
async-io = "0.1.3"
blocking = "0.4.7"
futures-lite = "0.1.5"
multitask = "0.2.0"
num_cpus = "1.13.0"
once_cell = "1.4.0"
blocking = "0.4.7"
[dependencies.tokio]
version = "0.2.21"
@ -47,7 +48,6 @@ async-tungstenite = { version = "0.7.1", features = ["async-native-tls"] }
base64 = "0.12.3"
ctrlc = "3.1.5"
futures = "0.3.5"
futures-lite = "0.1.5"
http = "0.2.1"
http-types = "2.3.0"
hyper = { version = "0.13.7", default-features = false, features = ["stream"] }

View File

@ -9,10 +9,8 @@
use std::net::{TcpStream, ToSocketAddrs};
use anyhow::{bail, Context as _, Error, Result};
use async_io::Async;
use blocking::{block_on, unblock};
use futures_lite::*;
use http_types::{Method, Request, Response};
use smol::{block_on, io::AsyncReadExt, unblock, Async};
use url::Url;
/// Sends a request and fetches the response.

View File

@ -16,12 +16,9 @@
use std::net::TcpListener;
use anyhow::Result;
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor};
use blocking::block_on;
use futures_lite::*;
use http_types::{Request, Response, StatusCode};
use smol::Task;
use smol::{block_on, future, Async, Task};
/// Serves a request and returns a response.
async fn serve(req: Request) -> http_types::Result<Response> {

View File

@ -14,9 +14,7 @@
use std::net::TcpStream;
use async_io::Async;
use blocking::{block_on, Unblock};
use futures_lite::*;
use smol::{block_on, future, io, Async, Unblock};
fn main() -> io::Result<()> {
block_on(async {

View File

@ -17,10 +17,7 @@ use std::net::{SocketAddr, TcpListener, TcpStream};
use async_channel::{bounded, Receiver, Sender};
use async_dup::Arc;
use async_io::Async;
use blocking::block_on;
use futures_lite::*;
use smol::Task;
use smol::{block_on, io, io::AsyncBufReadExt, io::AsyncWriteExt, stream::StreamExt, Async, Task};
/// An event on the chat server.
enum Event {

View File

@ -6,8 +6,7 @@
//! cargo run --example ctrl-c
//! ```
use blocking::block_on;
use futures_lite::*;
use smol::{block_on, future};
fn main() {
// Set a handler that sends a message through a channel.

View File

@ -6,20 +6,19 @@
//! cargo run --example hyper-client
//! ```
use std::io;
use std::net::Shutdown;
use std::net::{TcpStream, ToSocketAddrs};
use std::pin::Pin;
use std::task::{Context, Poll};
use anyhow::{bail, Context as _, Error, Result};
use async_io::Async;
use async_native_tls::TlsStream;
use blocking::{block_on, unblock};
use futures_lite::*;
use http::Uri;
use hyper::{Body, Client, Request, Response};
use smol::Task;
use smol::{
block_on, future::Future, io, io::AsyncRead, io::AsyncWrite, stream::StreamExt, unblock, Async,
Task,
};
/// Sends a request and fetches the response.
async fn fetch(req: Request<Body>) -> Result<Response<Body>> {

View File

@ -13,20 +13,18 @@
//!
//! Refer to `README.md` to see how to the TLS certificate was generated.
use std::io;
use std::net::Shutdown;
use std::net::{TcpListener, TcpStream};
use std::net::{Shutdown, TcpListener, TcpStream};
use std::pin::Pin;
use std::task::{Context, Poll};
use anyhow::{Error, Result};
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor, TlsStream};
use blocking::block_on;
use futures_lite::*;
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server};
use smol::Task;
use smol::{
block_on, future, future::Future, io, io::AsyncRead, io::AsyncWrite, ready, stream::Stream,
Async, Task,
};
/// Serves a request and returns a response.
async fn serve(req: Request<Body>, host: String) -> Result<Response<Body>> {

View File

@ -9,11 +9,9 @@
#[cfg(target_os = "linux")]
fn main() -> std::io::Result<()> {
use std::ffi::OsString;
use std::io;
use async_io::Async;
use blocking::block_on;
use inotify::{EventMask, Inotify, WatchMask};
use smol::{block_on, io, Async};
type Event = (OsString, EventMask);

View File

@ -8,12 +8,10 @@
#[cfg(target_os = "linux")]
fn main() -> std::io::Result<()> {
use std::io;
use std::os::unix::io::AsRawFd;
use std::time::{Duration, Instant};
use async_io::Async;
use blocking::block_on;
use smol::{block_on, io, Async};
use timerfd::{SetTimeFlags, TimerFd, TimerState};
/// Converts a [`nix::Error`] into [`std::io::Error`].

View File

@ -19,7 +19,7 @@
use std::time::{Duration, Instant};
use anyhow::{Error, Result};
use blocking::block_on;
use smol::block_on;
fn main() -> Result<()> {
block_on(async {

View File

@ -9,9 +9,7 @@
use std::net::{TcpStream, ToSocketAddrs};
use anyhow::{bail, Context as _, Result};
use async_io::Async;
use blocking::{block_on, unblock};
use futures_lite::*;
use smol::{block_on, io::AsyncReadExt, io::AsyncWriteExt, unblock, Async};
use url::Url;
/// Sends a GET request and fetches the response.

View File

@ -16,11 +16,8 @@
use std::net::{TcpListener, TcpStream};
use anyhow::Result;
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor};
use blocking::block_on;
use futures_lite::*;
use smol::Task;
use smol::{block_on, future, io::AsyncWriteExt, Async, Task};
const RESPONSE: &[u8] = br#"
HTTP/1.1 200 OK

View File

@ -14,9 +14,7 @@
use std::net::TcpStream;
use async_io::Async;
use blocking::{block_on, Unblock};
use futures_lite::*;
use smol::{block_on, future, io, Async, Unblock};
fn main() -> io::Result<()> {
block_on(async {

View File

@ -14,10 +14,7 @@
use std::net::{TcpListener, TcpStream};
use async_io::Async;
use blocking::block_on;
use futures_lite::*;
use smol::Task;
use smol::{block_on, io, Async, Task};
/// Echoes messages from the client back to it.
async fn echo(stream: Async<TcpStream>) -> io::Result<()> {

View File

@ -15,10 +15,8 @@
use std::net::TcpStream;
use anyhow::Result;
use async_io::Async;
use async_native_tls::{Certificate, TlsConnector};
use blocking::{block_on, Unblock};
use futures_lite::*;
use smol::{block_on, future, io, Async, Unblock};
fn main() -> Result<()> {
// Initialize TLS with the local certificate.

View File

@ -15,11 +15,8 @@
use std::net::{TcpListener, TcpStream};
use anyhow::Result;
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor, TlsStream};
use blocking::block_on;
use futures_lite::*;
use smol::Task;
use smol::{block_on, io, Async, Task};
/// Echoes messages from the client back to it.
async fn echo(stream: TlsStream<Async<TcpStream>>) -> Result<()> {

View File

@ -10,9 +10,7 @@
fn main() -> std::io::Result<()> {
use std::os::unix::net::UnixStream;
use async_io::Async;
use blocking::block_on;
use futures_lite::*;
use smol::{block_on, io::AsyncReadExt, Async};
block_on(async {
// Create a Unix stream that receives a byte on each signal occurrence.

View File

@ -10,9 +10,8 @@ use std::collections::{HashSet, VecDeque};
use anyhow::Result;
use async_channel::{bounded, Sender};
use blocking::block_on;
use scraper::{Html, Selector};
use smol::Task;
use smol::{block_on, Task};
const ROOT: &str = "https://www.rust-lang.org";

View File

@ -17,12 +17,10 @@ use std::pin::Pin;
use std::task::{Context, Poll};
use anyhow::{bail, Context as _, Result};
use async_io::Async;
use async_native_tls::{Certificate, TlsConnector, TlsStream};
use async_tungstenite::WebSocketStream;
use blocking::{block_on, unblock};
use futures::sink::{Sink, SinkExt};
use futures_lite::*;
use smol::{block_on, stream::Stream, stream::StreamExt, unblock, Async};
use tungstenite::handshake::client::Response;
use tungstenite::Message;
use url::Url;

View File

@ -17,13 +17,10 @@ use std::pin::Pin;
use std::task::{Context, Poll};
use anyhow::{Context as _, Result};
use async_io::Async;
use async_native_tls::{Identity, TlsAcceptor, TlsStream};
use async_tungstenite::WebSocketStream;
use blocking::block_on;
use futures::sink::{Sink, SinkExt};
use futures_lite::*;
use smol::Task;
use smol::{block_on, future, stream::Stream, stream::StreamExt, Async, Task};
use tungstenite::Message;
/// Echoes messages from the client back to it.

View File

@ -10,10 +10,7 @@
fn main() -> std::io::Result<()> {
use std::path::PathBuf;
use async_io::Async;
use blocking::{block_on, Unblock};
use futures_lite::*;
use smol::Task;
use smol::{block_on, io, io::AsyncWriteExt, Async, Task, Unblock};
use tempfile::tempdir;
use uds_windows::{UnixListener, UnixStream};

View File

@ -4,19 +4,6 @@
//! trivially simple codebase, this executor and its related crates offer performance and features
//! comparable to more complex frameworks like [tokio].
//!
//! Related async crates:
//!
//! * For async I/O and timers, use [`async-io`].
//! * For higher-level networking primitives, use [`async-net`].
//! * For executors, use [`multitask`].
//! * To call blocking code from async code or the other way around, use [`blocking`].
//! * For async traits and combinators, use [`futures-lite`].
//!
//! [`async-io`]: https://docs.rs/async-io
//! [`async-net`]: https://docs.rs/async-net
//! [`blocking`]: https://docs.rs/blocking
//! [`futures-lite`]: https://docs.rs/futures-lite
//! [`multitask`]: https://docs.rs/multitask
//! [`tokio`]: https://docs.rs/tokio
//!
//! # TCP server
@ -24,12 +11,10 @@
//! A simple TCP server that prints messages received from clients:
//!
//! ```no_run
//! use async_io::Async;
//! use blocking::{block_on, Unblock};
//! use smol::Task;
//! use smol::{block_on, io, Async, Task, Unblock};
//! use std::net::TcpListener;
//!
//! fn main() -> std::io::Result<()> {
//! fn main() -> io::Result<()> {
//! block_on(async {
//! // Start listening on port 9000.
//! let listener = Async::<TcpListener>::bind(([127, 0, 0, 1], 9000))?;
@ -44,7 +29,7 @@
//! let mut stdout = Unblock::new(std::io::stdout());
//!
//! // Copy data received from the client into stdout.
//! futures::io::copy(&stream, &mut stdout).await
//! io::copy(&stream, &mut stdout).await
//! });
//!
//! // Keep running the task in the background.
@ -166,7 +151,7 @@ impl<T> Task<T> {
T: Send + 'static,
{
static EXECUTOR: Lazy<Executor> = Lazy::new(|| {
for _ in 0..num_cpus::get().max(1) {
for _ in 0..2 {
thread::spawn(|| {
enter(|| {
let (p, u) = async_io::parking::pair();
@ -282,3 +267,13 @@ fn enter<T>(f: impl FnOnce() -> T) -> T {
})
}
}
#[doc(no_inline)]
pub use {
async_io::Async,
async_io::Timer,
blocking::{block_on, BlockOn},
blocking::{unblock, Unblock},
futures_lite::{future, io, stream},
futures_lite::{pin, ready},
};