8 releases (breaking)

new 0.7.0 Apr 6, 2024
0.6.0 Mar 8, 2023
0.5.1 Dec 22, 2021
0.4.0 Oct 1, 2021
0.1.1 Mar 23, 2021

#32 in #cloudflare-workers

Download history 17319/week @ 2023-12-18 2974/week @ 2023-12-25 5924/week @ 2024-01-01 8163/week @ 2024-01-08 7357/week @ 2024-01-15 12096/week @ 2024-01-22 7332/week @ 2024-01-29 8365/week @ 2024-02-05 9281/week @ 2024-02-12 3876/week @ 2024-02-19 10488/week @ 2024-02-26 4986/week @ 2024-03-04 9968/week @ 2024-03-11 8888/week @ 2024-03-18 13620/week @ 2024-03-25 14723/week @ 2024-04-01

47,564 downloads per month
Used in 25 crates (4 directly)

MIT/Apache

22KB
389 lines

worker-kv

Docs.rs Crates.io MIT Apache 2

Rust bindings to Cloudflare Worker KV Stores using wasm-bindgen and js-sys.

Example

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.

How do I use futures in WebAssembly?

There currently is not a way to use a Future natively from WebAssembly but with the future_to_promise function from wasm_bindgen_futures we can convert it to a standard JavaScript promise, which can be awaited in the regular JavaScript context.

Dependencies

~1.4–3.5MB
~69K SLoC