cxx icon indicating copy to clipboard operation
cxx copied to clipboard

Unclear how to get mutable reference out of a SharedPtr

Open scullionw opened this issue 4 years ago • 1 comments

From what I understand, to be able to call non const member functions, we need to have a mutable reference to a pinned object. Like:

fn getRouteIdsExt(feed: Pin<&mut Feed>) -> UniquePtr<CxxVector<i32>>;

However the Feed class in the c++ codebase inherits from std::enable_shared_from_this. This means I can only get SharedPtr's of it (instead of a UniquePtr), and I can't think of a way to get a mutable reference out of a SharedPtr.

In pure rust, to get interior mutability out of an Arc (which is the equivalent of shared_ptr), I can use a Mutex inside it, but I'm not sure what I can do here?

Is there any way to get mutability from a SharedPtr?

scullionw avatar Jun 14 '21 03:06 scullionw

See discussion in #537

adetaylor avatar Aug 09 '21 22:08 adetaylor