mirror of https://github.com/stjepang/smol
Update readme
This commit is contained in:
parent
1a542a8864
commit
933c12419b
31
README.md
31
README.md
|
@ -18,12 +18,11 @@ A small and fast async runtime.
|
||||||
Connect to an HTTP website, make a GET request, and pipe the response to the standard output:
|
Connect to an HTTP website, make a GET request, and pipe the response to the standard output:
|
||||||
|
|
||||||
```rust,no_run
|
```rust,no_run
|
||||||
use async_net::TcpStream;
|
use smol::{io, net, prelude::*, Unblock};
|
||||||
use smol::{io, prelude::*, Unblock};
|
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
smol::run(async {
|
smol::block_on(async {
|
||||||
let mut stream = TcpStream::connect("example.com:80").await?;
|
let mut stream = net::TcpStream::connect("example.com:80").await?;
|
||||||
let req = b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n";
|
let req = b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n";
|
||||||
stream.write_all(req).await?;
|
stream.write_all(req).await?;
|
||||||
|
|
||||||
|
@ -34,8 +33,8 @@ fn main() -> io::Result<()> {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This example uses [`async-net`] for networking, but you can also use the primitive `Async`
|
This example uses the `net` module for networking, but you can also use the primitive
|
||||||
type. See the [full code][get-request].
|
`Async` type. See the [full code][get-request].
|
||||||
|
|
||||||
Look inside the [examples] directory for more.
|
Look inside the [examples] directory for more.
|
||||||
|
|
||||||
|
@ -43,24 +42,6 @@ Look inside the [examples] directory for more.
|
||||||
[examples]: https://github.com/stjepang/smol/tree/master/examples
|
[examples]: https://github.com/stjepang/smol/tree/master/examples
|
||||||
[get-request]: https://github.com/stjepang/smol/blob/master/examples/get-request.rs
|
[get-request]: https://github.com/stjepang/smol/blob/master/examples/get-request.rs
|
||||||
|
|
||||||
## Compatibility
|
|
||||||
|
|
||||||
All async libraries work with smol out of the box.
|
|
||||||
|
|
||||||
The only exception is [tokio], which is traditionally incompatible with [futures] and crashes
|
|
||||||
when called from other executors. Fortunately, there are ways around it.
|
|
||||||
|
|
||||||
Enable the `tokio02` feature flag and `smol::run()` will create a minimal
|
|
||||||
tokio runtime for its libraries:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[dependencies]
|
|
||||||
smol = { version = "0.3", features = ["tokio02"] }
|
|
||||||
```
|
|
||||||
|
|
||||||
[tokio]: https://docs.rs/tokio
|
|
||||||
[futures]: https://docs.rs/futures
|
|
||||||
|
|
||||||
## TLS certificate
|
## TLS certificate
|
||||||
|
|
||||||
Some code examples are using TLS for authentication. The repository
|
Some code examples are using TLS for authentication. The repository
|
||||||
|
@ -75,7 +56,7 @@ The certificate file was generated using
|
||||||
[minica](https://github.com/jsha/minica) and
|
[minica](https://github.com/jsha/minica) and
|
||||||
[openssl](https://www.openssl.org/):
|
[openssl](https://www.openssl.org/):
|
||||||
|
|
||||||
```text
|
```
|
||||||
minica --domains localhost -ip-addresses 127.0.0.1 -ca-cert certificate.pem
|
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
|
openssl pkcs12 -export -out identity.pfx -inkey localhost/key.pem -in localhost/cert.pem
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue