9 releases (breaking)

0.8.0 Sep 25, 2024
0.7.0 Apr 6, 2024
0.6.0 Mar 8, 2023
0.5.1 Dec 22, 2021
0.1.1 Mar 23, 2021

#443 in Web programming

Download history 7851/week @ 2024-07-01 7922/week @ 2024-07-08 4087/week @ 2024-07-15 6993/week @ 2024-07-22 7004/week @ 2024-07-29 7407/week @ 2024-08-05 10343/week @ 2024-08-12 11336/week @ 2024-08-19 17001/week @ 2024-08-26 10629/week @ 2024-09-02 13079/week @ 2024-09-09 10686/week @ 2024-09-16 13338/week @ 2024-09-23 19853/week @ 2024-09-30 5879/week @ 2024-10-07 17164/week @ 2024-10-14

56,624 downloads per month
Used in 30 crates (4 directly)

MIT/Apache

23KB
420 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–4MB
~72K SLoC