Oh, but you also want to return the borrowed value without holding the lock? Rust doesn't allow this, at least not in safe code. The borrow checker would have to do whole program analysis (which it doesn't) to verify your claim that you'll never modify that value.
If you're really sure of yourself, you could get that value and unsafely mem::transmute
to a 'static
lifetime.
Even in your simplified example, this could go bad: calling register
with the same name
twice will drop the old value.