diff --git a/rust/src/storage/db/mod.rs b/rust/src/storage/db/mod.rs index 9729bc3953..447c357c20 100644 --- a/rust/src/storage/db/mod.rs +++ b/rust/src/storage/db/mod.rs @@ -33,8 +33,37 @@ pub trait DatabasePool: Send + Sync { /// Starts a transaction on the database and runs the given function, /// returning its result. /// + /// `name` should be a descriptive identifier for logging/metrics + /// /// `func` may be called multiple times under certain failure modes (like /// serialization and deadlock errors), so it is `Fn` rather than `FnOnce`. + /// + /// Usage: + /// ```rust + /// db_pool + /// .run_interaction(|txn| { + /// async move { + /// /* do stuff with txn */ + /// } + /// .boxed() + /// }) + /// ``` + // + // Ideally, this method signature would be slightly different to allow downstream + // usage to look like the following (simpler) but because allow the work to happen + // on other threads, the `Future` needs to be `Send`; As of 2026-06-22, the + // `AsyncFn` trait doesn't have a clean way to express that "the future this async + // closure produces is `Send`." + // ``` + // db_pool.run_interaction("description", async move |txn| { + // /* do stuff with txn */ + // }) + // ``` + // + // Refs: + // - [RFC 3668: Async closures](https://github.com/rust-lang/rfcs/pull/3668) + // - [RFC 3654: Return Type Notation](https://github.com/rust-lang/rfcs/pull/3654) + // - [Tracking Issue for return type notation](https://github.com/rust-lang/rust/issues/109417) fn run_interaction( &self, name: &'static str, diff --git a/rust/src/storage/store.rs b/rust/src/storage/store.rs index 4c8795726a..5a86e38e5e 100644 --- a/rust/src/storage/store.rs +++ b/rust/src/storage/store.rs @@ -63,7 +63,7 @@ impl Store

{ // // Owned copies so the callback can be `'static` (it may be moved to // another thread and called multiple times under retries). - let user_id = user_id.to_string(); + let user_id = user_id.to_owned(); let feature = feature.to_string(); let is_feature_enabled_for_user = self