If lock-ergonomicsⓒ is as relevant to you as indexing, you're doing it wrong.
I would rather take indexing returning Results than the other way around.
One can always wrap any code in {||{ //.. }}() and use question marks liberally anyway (I call them stable try blocks 😉).
if you're really that bothered..
use std::sync::{Mutex, MutexGuard}; trait ULock<'a> { type Guard; fn ulock(&'a self) -> Self::Guard; } impl<'a, T: 'a> ULock<'a> for Mutex<T> { type Guard = MutexGuard<'a, T>; fn ulock(&'a self) -> Self::Guard { self.lock().unwrap() } }or use a wrapper struct, if you really really want the method to be called exactly
lock.