Fix the wrapper picker for shared Rust config
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 asread_onlyorwrite_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>, thenRc<T>.read_mostly_mutable:Arc<RwLock<T>>, thenRc<RefCell<T>>.write_heavy_mutable:Arc<Mutex<T>>, thenRc<RefCell<T>>.boxed_closure:Box<dyn Fn() + Send + Sync>, thenBox<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
Input
choose_sharing_wrappers(["read_only", "read_mostly_mutable"], True)Output
["Arc<T>", "Arc<RwLock<T>>"]Example 2
Input
choose_sharing_wrappers(["read_only", "read_mostly_mutable"], False)Output
["Rc<T>", "Rc<RefCell<T>>"]Example 3
Input
choose_sharing_wrappers(["boxed_closure"], True)Output
["Box<dyn Fn() + Send + Sync>"]