Skip to content

Instantly share code, notes, and snippets.

@thomasantony
Created January 10, 2022 22:30
Show Gist options
  • Save thomasantony/57442869a6cc41f25d8a09a558283761 to your computer and use it in GitHub Desktop.
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
#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