pub unsafe trait Class<S> {
    fn as_ptr(&self) -> *const S;
    fn as_mut_ptr(&mut self) -> *mut S;
}
Expand description

Trait for getting raw pointers for FFI calls, used to provide default implementations of traits that “re-object” a C wrapper of a C++ library.

Safety

Implementing Class<S> for T where S is not a superclass of T will cause Undefined Behaviour.

This trait may hide a raw pointer cast from *Self to *T. It is intended for use in default implementations for traits wrapping C++ classes. In C++-land this is just how things are done, but From Rust’s perspective, this is madness. The relations defined between types using this trait must align with the C++ class hierarchy. The [Inherit] trait can be used to simplify implementing Class<S> for T where T: Class<T>.

Required Methods

Returns a raw const pointer to the wrapped type. Retrieving a raw pointer is safe. However, pretty much any use of a raw pointer is unsafe. In particular: this pointer should not be used to construct a second owning wrapper around the pointer.

Returns a raw mut pointer to the wrapped type. Retrieving a raw pointer is safe. However, pretty much any use of a raw pointer is unsafe. In particular: this pointer should not be used to construct a second owning wrapper around the pointer.

Implementations on Foreign Types

Implementors