Trying to return reference from RwLock, “borrowed value does not live long enough” Error
问题 I've been working on my first Rust project recently but have hit a snag. I am using a HashMap mapping String s to AtomicUsize integers. The HashMap is protected by a RwLock to allow for concurrent access. I would like to be able to return references to AtomicUsize values in the HashMap , however if I try to return these references to the caller past the lifetime of the RwLockWriteGuard I get an error that borrowed value does not live long enough . I've reproduced a minimal example below and