Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
zebp committed Apr 6, 2024
1 parent 3c53503 commit 4b3c570
Showing 1 changed file with 1 addition and 39 deletions.
40 changes: 1 addition & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
# worker-kv

[![Docs.rs][docs-badge]][docs-url]
[![Crates.io][crates-badge]][crates-url]
[![MIT][mit-license-badge]][mit-license-url]
[![Apache 2][apache-license-badge]][apache-license-url]

[crates-badge]: https://img.shields.io/crates/v/worker-kv.svg
[crates-url]: https://crates.io/crates/worker-kv
[mit-license-badge]: https://img.shields.io/badge/license-MIT-blue.svg
[apache-license-badge]: https://img.shields.io/badge/license-Apache2-blue.svg
[mit-license-url]: https://github.com/zebp/worker-kv/blob/master/LICENSE-MIT
[apache-license-url]: https://github.com/zebp/worker-kv/blob/master/LICENSE-APACHE
[docs-badge]: https://img.shields.io/badge/docs.rs-rustdoc-green
[docs-url]: https://docs.rs/worker-kv/

Rust bindings to Cloudflare Worker [KV Stores](https://developers.cloudflare.com/workers/runtime-apis/kv) using [wasm-bindgen](https://docs.rs/wasm-bindgen) and [js-sys](https://docs.rs/js-sys).

## Example

```rust
let kv = KvStore::create("Example")?; // or KvStore::from_this(&this, "Example") if using modules format Workers

// Insert a new entry into the kv.
kv.put("example_key", "example_value")?
.metadata(vec![1, 2, 3, 4]) // Use some arbitrary serialiazable metadata
.execute()
.await?;

// NOTE: kv changes can take a minute to become visible to other workers.
// Get that same metadata.
let (value, metadata) = kv.get("example_key").text_with_metadata::<Vec<usize>>().await?;
```

For a more complete example check out the full [example](example).

## How do I use futures in WebAssembly?

There currently is not a way to use a [Future](https://doc.rust-lang.org/stable/std/future/trait.Future.html) natively from WebAssembly but with the [future_to_promise](https://docs.rs/wasm-bindgen-futures/0.4.22/wasm_bindgen_futures/fn.future_to_promise.html) function from [wasm_bindgen_futures](https://docs.rs/wasm_bindgen_futures) we can convert it to a standard JavaScript promise, which can be awaited in the regular JavaScript context.
This crate has been moved to the [workers-rs](https://github.com/cloudflare/workers-rs/tree/main/worker-kv) repository.

0 comments on commit 4b3c570

Please sign in to comment.