The following code compiles with a warning (on take
function):
function cannot return without recursing
aloop
may express intention better if this is on purpose
use std::ops::Deref;
pub trait MutexGuard<T>: Deref<Target = T> /*+ DerefMut<Target = T>*/ {
fn set(&mut self, value: T);
fn take(&self) -> Option<T>;
}
impl<T> MutexGuard<T> for tokio::sync::MutexGuard<'_, T> {
fn set(&mut self, value: T) {
*self.deref_mut() = value;
}
fn take(&self) -> Option<T> {
tokio::sync::MutexGuard::take(self)
}
}
Is there any way to make it work without renaming take
? I also don’t understand why the current version does not work (I specified the “full path” to the function tokio::sync::MutexGuard::take
. Why does Rust use a trait instead?)