dimforge / ncollide

2 and 3-dimensional collision detection library in Rust.
https://ncollide.org
Apache License 2.0
921 stars 105 forks source link

Get Arc<dyn Shape> from ShapeHandle #350

Closed ColonelThirtyTwo closed 4 years ago

ColonelThirtyTwo commented 4 years ago

Doing some C interop. ShapeHandle appears to wrap Arc<dyn Shape>, and while there's a method to convert an Arc<dyn Shape> to a ShapeHandle, there's no way to get the Arc<dyn Shape> from an existing ShapeHandle.

I'd like this because then I can expose the pointer provided by Arc::into_raw to the C API, however since I can't do that, I have to box a ShapeHandle, which adds another layer of allocation and indirection.

sebcrozet commented 4 years ago

Hi @ColonelThirtyTwo! If that can be useful to you, we could add an into_inner method to ShapeHandle:

impl<N: RealField> ShapeHandle<N> {
     pub fn into_inner(self) -> Arc<dyn Shape<N>> {
         self.0
     }
}