Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
cksac committed Oct 24, 2023
1 parent faaac56 commit 1024b76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dataloader"
version = "0.16.0"
version = "0.17.0"
edition = "2018"
authors = ["cksac <[email protected]>"]
description = "Rust implementation of Facebook's DataLoader using async-await."
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,36 @@ Rust implementation of [Facebook's DataLoader](https://github.com/facebook/datal
## Usage
### Switching runtime, by using cargo features
- `runtime-async-std` (default), to use the [async-std](https://async.rs) runtime
- dataloader = "0.16"
- dataloader = "0.17"
- `runtime-tokio` to use the [Tokio](https://tokio.rs) runtime
- dataloader = { version = "0.16", default-features = false, features = ["runtime-tokio"]}
- dataloader = { version = "0.17", default-features = false, features = ["runtime-tokio"]}


### Add to your `Cargo.toml`:
```toml
[dependencies]
dataloader = "0.16"
dataloader = "0.17"
futures = "0.3"
async-trait = "0.1"
```

### Example:
```rust
use async_trait::async_trait;
use dataloader::cached::Loader;
use dataloader::BatchFn;
use futures::executor::block_on;
use futures::future::ready;
use std::collections::HashMap;
use std::thread;

struct MyLoadFn;

#[async_trait]
impl BatchFn<usize, usize> for MyLoadFn {
async fn load(&mut self, keys: &[usize]) -> HashMap<usize, usize> {
println!("BatchFn load keys {:?}", keys);
keys.iter()
let ret = keys.iter()
.map(|v| (v.clone(), v.clone()))
.collect::<HashMap<_, _>>()
.collect::<HashMap<_, _>>();
ready(ret).await
}
}

Expand Down

0 comments on commit 1024b76

Please sign in to comment.