Created
January 10, 2022 22:30
-
-
Save thomasantony/57442869a6cc41f25d8a09a558283761 to your computer and use it in GitHub Desktop.
An implementation of unique_ptr to wrap a rust Box type from cxx.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "rust/cxx.h" | |
#include <memory> | |
using std::shared_ptr; | |
using std::unique_ptr; | |
using rust::Box; | |
template <typename T> struct BoxDeleter { | |
void operator()(T* ptr){ | |
Box<T> val = Box<T>::from_raw(ptr); | |
} | |
}; | |
template <typename T> | |
unique_ptr<T, BoxDeleter<T>> box_to_uptr(Box<T>&& box) | |
{ | |
return unique_ptr<T, BoxDeleter<T>>(box.into_raw(), BoxDeleter<T>()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment