https://pantsbuild.org/ logo
#development
Title
# development
h

hundreds-breakfast-49010

11/11/2019, 11:04 PM
does anyone know if there's a way in rust to map into a
Mutex
?
a

aloof-angle-91616

11/11/2019, 11:04 PM
what do you mean by "map into" here?
h

hundreds-breakfast-49010

11/11/2019, 11:05 PM
i.e. if I have
Arc<Mutex<T>>
and
T
has some function
&self -> foo
on it, can I easily get a
Arc<Mutex<foo>>
?
a

aloof-angle-91616

11/11/2019, 11:05 PM
ooh, great question
my first thought is that you'd at least need to make a new
Arc
, since you can't stick it in the same spot as the old one
and then my next thought was that you'd probably have to make a new
Mutex<>
too, since mutexes are paired with types in rust, so i was going to look through the constructors for Mutex
would you want to Drop the old
Arc<Mutex<T>>
at the same time?
h

hundreds-breakfast-49010

11/11/2019, 11:08 PM
nah
basically I'm trying to make the type contained within an
Arc<Mutex<_>>
in
WorkUnitStore
more complicated
without changing the contract provided by
get_workunits
and I'm not sure what hte cleanest way to do this is
a

aloof-angle-91616

11/11/2019, 11:09 PM
i was thinking that
Arc::new(Mutex::new(self.get_foo())
would make sense, but not sure if you can construct a mutex like that
lmk if that doesn't work or doesn't sound right
h

hundreds-breakfast-49010

11/11/2019, 11:15 PM
so, I would already have to unlock the first mutex to wrap part of the contained value in a new mutex
I'm not sure this works