smol/README.md

122 lines
4.8 KiB
Markdown
Raw Permalink Normal View History

2020-04-16 14:09:22 +00:00
# smol
2023-10-18 12:47:03 +00:00
[![Build](https://github.com/smol-rs/smol/actions/workflows/ci.yml/badge.svg)](
2020-12-23 20:31:12 +00:00
https://github.com/smol-rs/smol/actions)
[![License](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg)](
2020-12-23 20:31:12 +00:00
https://github.com/smol-rs/smol)
2020-04-21 17:36:05 +00:00
[![Cargo](https://img.shields.io/crates/v/smol.svg)](
https://crates.io/crates/smol)
[![Documentation](https://docs.rs/smol/badge.svg)](
https://docs.rs/smol)
[![Chat](https://img.shields.io/matrix/smol-rs%3Amatrix.org)](
https://matrix.to/#/#smol-rs:matrix.org)
2020-04-16 14:09:22 +00:00
<img src="https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png" alt="kitty" width="100px" style="float: left;" />
2020-07-23 10:24:16 +00:00
A small and fast async runtime.
2020-02-06 14:09:00 +00:00
2020-08-30 20:32:10 +00:00
This crate simply re-exports other smaller async crates (see the source).
To use tokio-based libraries with smol, apply the [`async-compat`] adapter to futures and I/O
types.
2020-07-23 10:24:16 +00:00
## Examples
2020-02-06 14:09:00 +00:00
2020-07-23 10:24:16 +00:00
Connect to an HTTP website, make a GET request, and pipe the response to the standard output:
2020-02-04 10:27:09 +00:00
```rust,no_run
2020-08-26 22:00:34 +00:00
use smol::{io, net, prelude::*, Unblock};
2020-04-21 17:36:05 +00:00
2020-07-23 10:24:16 +00:00
fn main() -> io::Result<()> {
2020-08-26 22:00:34 +00:00
smol::block_on(async {
let mut stream = net::TcpStream::connect("example.com:80").await?;
2020-07-23 10:24:16 +00:00
let req = b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n";
stream.write_all(req).await?;
2020-05-03 16:28:19 +00:00
2020-07-23 10:24:16 +00:00
let mut stdout = Unblock::new(std::io::stdout());
2020-09-20 16:29:46 +00:00
io::copy(stream, &mut stdout).await?;
2020-07-23 10:24:16 +00:00
Ok(())
})
}
```
2020-08-30 20:32:10 +00:00
There's a lot more in the [examples] directory.
2020-04-21 17:36:05 +00:00
2020-08-30 20:32:10 +00:00
[`async-compat`]: https://docs.rs/async-compat
2020-12-23 20:31:12 +00:00
[examples]: https://github.com/smol-rs/smol/tree/master/examples
[get-request]: https://github.com/smol-rs/smol/blob/master/examples/get-request.rs
2020-04-21 17:36:05 +00:00
2020-10-14 21:48:24 +00:00
## Subcrates
- [async-channel] - Multi-producer multi-consumer channels
- [async-executor] - Composable async executors
- [async-fs] - Async filesystem primitives
- [async-io] - Async adapter for I/O types, also timers
- [async-lock] - Async locks (barrier, mutex, reader-writer lock, semaphore)
- [async-net] - Async networking primitives (TCP/UDP/Unix)
- [async-process] - Async interface for working with processes
- [async-task] - Task abstraction for building executors
- [blocking] - A thread pool for blocking I/O
- [futures-lite] - A lighter fork of [futures]
- [polling] - Portable interface to epoll, kqueue, event ports, and wepoll
2020-12-23 20:31:12 +00:00
[async-io]: https://github.com/smol-rs/async-io
[polling]: https://github.com/smol-rs/polling
[nb-connect]: https://github.com/smol-rs/nb-connect
[async-executor]: https://github.com/smol-rs/async-executor
[async-task]: https://github.com/smol-rs/async-task
[blocking]: https://github.com/smol-rs/blocking
[futures-lite]: https://github.com/smol-rs/futures-lite
[smol]: https://github.com/smol-rs/smol
[async-net]: https://github.com/smol-rs/async-net
[async-process]: https://github.com/smol-rs/async-process
[async-fs]: https://github.com/smol-rs/async-fs
[async-channel]: https://github.com/smol-rs/async-channel
[concurrent-queue]: https://github.com/smol-rs/concurrent-queue
[event-listener]: https://github.com/smol-rs/event-listener
[async-lock]: https://github.com/smol-rs/async-lock
[fastrand]: https://github.com/smol-rs/fastrand
2020-10-14 21:48:24 +00:00
[futures]: https://github.com/rust-lang/futures-rs
2020-04-21 17:36:05 +00:00
## TLS certificate
2020-04-27 23:29:30 +00:00
Some code examples are using TLS for authentication. The repository
2020-04-28 11:09:59 +00:00
contains a self-signed certificate usable for testing, but it should **not**
be used for real-world scenarios. Browsers and tools like curl will
show this certificate as insecure.
In browsers, accept the security prompt or use `curl -k` on the
command line to bypass security warnings.
2020-04-21 17:36:05 +00:00
The certificate file was generated using
[minica](https://github.com/jsha/minica) and
[openssl](https://www.openssl.org/):
2020-04-20 15:45:14 +00:00
2020-08-26 22:04:00 +00:00
```text
2020-04-21 17:36:05 +00:00
minica --domains localhost -ip-addresses 127.0.0.1 -ca-cert certificate.pem
openssl pkcs12 -export -out identity.pfx -inkey localhost/key.pem -in localhost/cert.pem
2020-04-20 15:45:14 +00:00
```
2020-07-23 13:04:13 +00:00
Another useful tool for making certificates is [mkcert].
[mkcert]: https://github.com/FiloSottile/mkcert
2023-01-15 02:42:17 +00:00
## MSRV Policy
The Minimum Supported Rust Version (MSRV) of this crate is **1.63**. As a **tentative** policy, the MSRV will not advance past the [current Rust version provided by Debian Stable](https://packages.debian.org/stable/rust/rustc). At the time of writing, this version of Rust is *1.63*. However, the MSRV may be advanced further in the event of a major ecosystem shift or a security vulnerability.
2023-01-15 02:42:17 +00:00
2020-02-04 10:27:09 +00:00
## License
2020-04-21 17:36:05 +00:00
Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
2020-02-04 10:27:09 +00:00
2020-04-21 17:36:05 +00:00
#### Contribution
2020-02-04 10:27:09 +00:00
Unless you explicitly state otherwise, any contribution intentionally submitted
2020-04-21 17:36:05 +00:00
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.