Is it appropriate to use Box::from_raw to wrap the pointer and take ownership of it?
The documentation for from_raw answers this for you:
Since the way Box allocates and releases memory is unspecified, the only valid pointer to pass to this function is the one taken from another Box via the
Box::into_rawfunction.
which means that your current usage is unspecified.
I also want to implement the Drop Trait on the Key, such that the destructor function keyDel is automatically called
You should not implement Drop for Key because Key is not allocated by Rust. You would ideally make your own wrapper type that uses its own drop to call keyDel with the pointer. For instance:
struct KeyWrapper { ptr: NonNull<Key> } impl Drop for KeyWrapper { fn drop(&mut self) { keyDel(self.ptr.as_ptr()) } } impl KeyWrapper { fn new() { KeyWrapper { ptr: NonNull::new(keyNew(0 as *const i8)) } } fn someUtil(&self) { // As an example, you could call through to some C function. keySomeUtil(self.ptr.as_ptr()) } } This way on the Rust side you are only interacting with the type that wraps the pointer, and it will call keyDel when it is dropped. It is your job to make sure this wrapper type only performs safe operations via the C API so as not to invalidate Rust's safety guarantees.
Related: