-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible for the ArcMutexGuard
to be more flexible?
#328
Comments
What if |
Oh, it's terrible, I can even construct one using safe rust. struct Foo {
impls: [Mutex<FooImpl>; 2],
}
impl AsRef<Mutex<FooImpl>> for Foo {
fn as_ref(&self) -> &Mutex<FooImpl> {
static IDX: AtomicUsize = AtomicUsize::new(0);
&self[IDX.fetch_add(1, Relaxed) % 2]
}
}
struct FooImpl(u32);
let foo = Foo::new(impls: [Mutex::new(FooImpl(0)), Mutex::new(FooImpl(1))]); Is it possible to prevent this? |
I think the only way is to use a new unsafe trait instead of |
An unsafe trait seems feasible. But I can't help asking myself, no safer way? Now how I hope there can be associated fields in traits. |
I'm using the
arc_lock
feature and it requiresself: &Arc<Self>
in theMutex::lock_arc
function. But in my case, it is a little bit inconvenient.But it is not allowed to call
lock_arc
for the_impl
in aArc<Foo>
because the signature doesn't match.I hope the
lock_arc
could accept anything likethis: &Arc<impl AsRef<Self>>
whereSelf
is theMutex
type. In that way, if Iimpl AsRef<Mutex<FooImpl>> for Foo
, then I can callMutex::lock_arc(&*self)
to acquire a mutex guard ofFooImpl
whereself
's type is&Arc<Foo>
.To extend the
lock_arc
tolock_arc(this: &Arc<impl AsRef<Self>>
may be a break change, but it can be resolved via a different feature gate likearc_lock_ext
or renamelock_arc
tolock_in_arc
or something else.Do you think it is feasible?
The text was updated successfully, but these errors were encountered: