Fix the wrapper picker for shared Rust config

Review the AI's codeEasy10 min

Your task

Your Rust service shares a Config struct across worker threads. An AI first derived Clone, then fought the borrow checker, then wrapped everything in Rc<RefCell<Config>>, which does not compile across threads: Rc is not Send and RefCell is not Sync. Your team now picks a wrapper per field from how the field is used.

An assistant wrote choose_sharing_wrappers(field_kinds, cross_thread). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • field_kinds: how each field is used, such as read_only or write_heavy_mutable.
  • cross_thread: true when the config is shared across OS threads.
  • Return one wrapper per field, in order.

Rules the tests check. Kinds compare exactly. With cross_thread true, then false:

  • read_only: Arc<T>, then Rc<T>.
  • read_mostly_mutable: Arc<RwLock<T>>, then Rc<RefCell<T>>.
  • write_heavy_mutable: Arc<Mutex<T>>, then Rc<RefCell<T>>.
  • boxed_closure: Box<dyn Fn() + Send + Sync>, then Box<dyn Fn()>.
  • Any other kind, an empty one included: unsupported, either way.

Examples

choose_sharing_wrappers(field_kinds: list[str], cross_thread: bool) -> list[str]
Example 1
Inputchoose_sharing_wrappers(["read_only", "read_mostly_mutable"], True)
Output["Arc<T>", "Arc<RwLock<T>>"]
Example 2
Inputchoose_sharing_wrappers(["read_only", "read_mostly_mutable"], False)
Output["Rc<T>", "Rc<RefCell<T>>"]
Example 3
Inputchoose_sharing_wrappers(["boxed_closure"], True)
Output["Box<dyn Fn() + Send + Sync>"]