This repository has been archived by the owner on Apr 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
1 addition
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |