mirror of https://github.com/stjepang/smol
Reexport other crates into smol
This commit is contained in:
parent
b3005d9420
commit
39f67144a4
|
@ -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"] }
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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>> {
|
||||
|
|
|
@ -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>> {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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`].
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<()> {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<()> {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
33
src/lib.rs
33
src/lib.rs
|
@ -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},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue