I just looked into ManuallyDrop. Thanks for the hint. I think I will go for this one, as it also doesn't automatically dereference T
if T
is &T
like mem::forget
does.
Edit for the solution:
fn do_something<T> (data: T) {
// Expose address of data here to device
// After this call, data will NOT be cleaned up.
// Memory must be cleaned up manually.
ManuallyDrop::new(data);
}
This should work fine even when T
is of type &T
.