pub unsafe trait MakeCppStorage: Sized {
// Required methods
unsafe fn allocate_uninitialized_cpp_storage() -> *mut Self;
unsafe fn free_uninitialized_cpp_storage(ptr: *mut Self);
}
Expand description
A type which has the ability to create heap storage space for itself in C++, without initializing that storage.
§Safety
Implementers must ensure that the pointer returned by
allocate_uninitialized_cpp_storage
is a valid, non-null,
pointer to a new but uninitialized storage block, and that
such blocks must be freeable using either of these routes:
- before they’re initialized, using
free_uninitialized_cpp_storage
- after they’re initialized, via a delete expression like
delete p;
Required Methods§
Sourceunsafe fn allocate_uninitialized_cpp_storage() -> *mut Self
unsafe fn allocate_uninitialized_cpp_storage() -> *mut Self
Allocates heap space for this type in C++ and return a pointer to that space, but do not initialize that space (i.e. do not yet call a constructor).
§Safety
To avoid memory leaks, callers must ensure that this space is
freed using free_uninitialized_cpp_storage
, or is converted into
a UniquePtr
such that it can later be freed by
std::unique_ptr<T, std::default_delete<T>>
.
Sourceunsafe fn free_uninitialized_cpp_storage(ptr: *mut Self)
unsafe fn free_uninitialized_cpp_storage(ptr: *mut Self)
Frees a C++ allocation which has not yet had a constructor called.
§Safety
Callers guarantee that the pointer here was allocated by
allocate_uninitialized_cpp_storage
and has not been
initialized.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.