workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

Remove unnecessary Copy constraint on `durable::Storage::transaction()`

Open rozbb opened this issue 9 months ago • 0 comments

Currently, durable::Storage::transaction requires that its closure implement Copy. This is way too strong a requirement, since you can't even do things like:

let key: String = get_dur_obj_key();
storage.transaction(move |tx| async move {
    let val = tx.get(&key).await?;
});

The compiler yells, saying the trait bound String: std::marker::Copy is not satisfied in {closure@...}.

Fortunately, there's no inherent reason why this closure needs to implement Copy. This PR changes the transaction semantics to make use of wasm_bindgen's built-in FnOnce support for futures.

rozbb avatar Mar 04 '25 18:03 rozbb