Skip to content

Commit

Permalink
Update rust docs (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnbln authored Aug 19, 2023
1 parent ca08cfe commit 0804e69
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/examples/unofficial/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

```toml
[dependencies]
nekosbest = "0.19"
nekosbest = "0.20"
```

## Example
Expand Down Expand Up @@ -116,6 +116,44 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
```

## Downloading the images.

With the `download` feature, you can download the images directly, like so:

```rust, noplaypen
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let resp = nekosbest::get(nekosbest::Category::Neko).await?;
let image = nekosbest::download::download(&resp).await?;
// maybe also save, or just use it directly
tokio::task::spawn_blocking(move || image.save("neko.png")).await??;
// or alternatively, if you just want to save it, without
// loading the whole image in-memory:
nekosbest::download::download_to_file(&resp, "neko.png").await?;
Ok(())
}
```

Or directly from a given URL:

```rust, noplaypen
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// let resp = nekosbest::get(nekosbest::Category::Neko).await?;
// let url: String = resp.url;
let url = "https://nekos.best/api/v2/neko/1efcda2d-d0d3-4e96-9b40-86852374b4bc.png".to_owned();
let image = nekosbest::download::download_from_url(&url).await?;
tokio::task::spawn_blocking(move || image.save("neko.png")).await??;
// or alternatively, if you just want to save it, without
// loading the whole image in-memory:
nekosbest::download::download_from_url_to_file(&url, "neko.png").await?;
Ok(())
}
```

## Blocking client

All functions become blocking when used with the "blocking" feature.
Expand Down

0 comments on commit 0804e69

Please sign in to comment.