7 releases (breaking)

0.6.0 Mar 8, 2023
0.5.1 Dec 22, 2021
0.4.0 Oct 1, 2021
0.3.0 Aug 10, 2021
0.1.1 Mar 23, 2021

#290 in Network programming

Download history 1856/week @ 2023-02-08 1581/week @ 2023-02-15 1911/week @ 2023-02-22 1728/week @ 2023-03-01 1449/week @ 2023-03-08 1773/week @ 2023-03-15 1036/week @ 2023-03-22 1007/week @ 2023-03-29 962/week @ 2023-04-05 1366/week @ 2023-04-12 913/week @ 2023-04-19 1101/week @ 2023-04-26 851/week @ 2023-05-03 842/week @ 2023-05-10 1015/week @ 2023-05-17 839/week @ 2023-05-24

3,639 downloads per month
Used in 21 crates (3 directly)

MIT/Apache

22KB
387 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.6–3.5MB
~71K SLoC