More docs

This commit is contained in:
Stjepan Glavina 2020-04-19 11:29:52 +02:00
parent 7fca86af40
commit a58a03d63b
8 changed files with 963 additions and 529 deletions

View File

@ -12,9 +12,9 @@ crossbeam = "0.7.3"
futures = { version = "0.3.4", default-features = false, features = ["std"] }
once_cell = "1.3.1"
piper = { path = "piper" }
scoped-tls = "1.0.0"
scoped-tls-hkt = "0.1.2"
slab = "0.4.2"
socket2 = { version = "0.3.12", features = ["pair"] }
socket2 = { version = "0.3.12", features = ["pair", "unix"] }
# Optional feature for seamless integration with crates depending on tokio.
# It creates a global tokio runtime and sets up its context inside smol.
@ -24,7 +24,11 @@ socket2 = { version = "0.3.12", features = ["pair"] }
# [dependencies]
# smol = { version = "1", features = ["tokio"] }
# ```
tokio = { version = "0.2.18", default-features = false, optional = true }
[dependencies.tokio]
version = "0.2.18"
default-features = false
features = ["rt-threaded"]
optional = true
[target.'cfg(unix)'.dependencies]
nix = "0.17.0"
@ -41,7 +45,7 @@ timerfd = "1.1.1"
[dev-dependencies]
anyhow = "1.0.28"
async-h1 = "1.1.1"
async-h1 = "1.1.2"
async-native-tls = "0.3.3"
async-std = "1.5.0"
async-tungstenite = { version = "0.4.2", features = ["async-native-tls"] }
@ -56,7 +60,8 @@ reqwest = "0.10.4"
scraper = "0.11.0"
signal-hook = "0.1.13"
smol = { path = ".", features = ["tokio"] }
surf = "1.0.3"
tokio = { package = "tokio", version = "0.2.18", default-features = false, features = ["rt-threaded"] }
surf = { version = "2.0.0-alpha.1", default-features = false, features = ["h1-client"] }
tempfile = "3.1.0"
tokio = { version = "0.2.18", default-features = false }
tungstenite = "0.10.1"
url = "2.1.1"

View File

@ -9,7 +9,7 @@ A small and fast async runtime.
* Safe - Written in 100% safe Rust.
* Complete - Fully featured and ready for production.
* Documented - Simple code, easy to understand and modify.
* Lightweight - Small dependencies, relies on epoll/kqueue/WSAPoll.
* Lightweight - Small dependencies, relies on epoll/kqueue/wepoll.
* Portable - Linux, Android, macOS, iOS, Windows, FreeBSD, OpenBSD, NetBSD, DragonFly BSD.
## Features

7
examples/compat-surf.rs Normal file
View File

@ -0,0 +1,7 @@
fn main() -> http_types::Result<()> {
smol::run(async {
let body = surf::get("https://www.rust-lang.org").recv_string().await?;
println!("{:?}", body);
Ok(())
})
}

View File

@ -1,3 +1,6 @@
// Uses the `ctrlc` crate to set a handler that sends a message
// through an async channel.
use futures::prelude::*;
fn main() {

View File

@ -5,12 +5,13 @@ use std::fs;
use futures::io;
use futures::prelude::*;
use smol::blocking;
fn main() -> io::Result<()> {
let path = env::args().nth(1).expect("missing path argument");
smol::run(async move {
let mut dir = smol::iter(smol::blocking!(fs::read_dir(path))?);
let mut dir = smol::iter(blocking!(fs::read_dir(path))?);
while let Some(res) = dir.next().await {
println!("{}", res?.file_name().to_string_lossy());

View File

@ -36,16 +36,10 @@ fn main() -> Result<()> {
let mut tasks = 0;
while queue.len() + tasks > 0 {
// Limit the number of concurrent requests.
while tasks < 200 {
match queue.pop_front() {
None => break,
Some(url) => {
println!("{}", url);
tasks += 1;
Task::spawn(fetch(url, s.clone())).detach();
}
}
while let Some(url) = queue.pop_front() {
println!("{}", url);
tasks += 1;
Task::spawn(fetch(url, s.clone())).detach();
}
let body = match r.try_recv() {

View File

@ -1,11 +1,11 @@
#[cfg(windows)]
fn main() -> std::io::Result<()> {
use std::fs;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use futures::io;
use futures::prelude::*;
use smol::{Async, Task};
use tempfile::tempdir;
use uds_windows::{UnixListener, UnixStream};
async fn client(addr: PathBuf) -> io::Result<()> {
@ -17,16 +17,16 @@ fn main() -> std::io::Result<()> {
Ok(())
}
let path = "socket";
let _ = fs::remove_file(path);
let dir = tempdir()?;
let path = dir.path().join("socket");
smol::run(async {
// Create a listener.
let listener = Async::new(UnixListener::bind(path)?)?;
let listener = Async::new(UnixListener::bind(&path)?)?;
println!("Listening on {:?}", listener.get_ref().local_addr()?);
// Spawn a client task.
let task = Task::spawn(client(path.into()));
let task = Task::spawn(client(path));
// Accept the client.
let (stream, _) = listener.with(|l| l.accept()).await?;

1434
src/lib.rs

File diff suppressed because it is too large Load Diff