pub unsafe trait HarfbuzzObject: Sized {
type Raw;
// Required methods
fn as_raw(&self) -> *mut Self::Raw;
unsafe fn reference(&self);
unsafe fn dereference(&self);
// Provided method
fn as_raw_mut(&mut self) -> *mut Self::Raw { ... }
}
Expand description
A trait which is implemented for all harffbuzz wrapper structs. It exposes common functionality for converting from and to the underlying raw harfbuzz pointers that are useful for ffi.
§Safety
This trait may only be implemented for structs that are zero-sized and is therefore unsafe to implement.
Required Associated Types§
Required Methods§
Sourcefn as_raw(&self) -> *mut Self::Raw
fn as_raw(&self) -> *mut Self::Raw
Returns the underlying harfbuzz object pointer.
The caller must ensure, that this pointer is not used after self
’s
destruction.
Sourceunsafe fn reference(&self)
unsafe fn reference(&self)
Increases the reference count of the HarfBuzz object.
Wraps a hb_TYPE_reference()
call.
§Safety
While no undefined behavior can be introduced only by increasing the reference count (I think) this method is still marked unsafe since there should be no need for it to be called from safe code.
Sourceunsafe fn dereference(&self)
unsafe fn dereference(&self)
Decreases the reference count of the HarfBuzz object and destroys it if the reference count reaches zero.
Wraps a hb_TYPE_destroy()
call.
§Safety
You always have to call reference
first before using this method.
Otherwise you might accidentally hold on to already destroyed objects
and causing UB.
Provided Methods§
Sourcefn as_raw_mut(&mut self) -> *mut Self::Raw
fn as_raw_mut(&mut self) -> *mut Self::Raw
Returns the underlying harfbuzz object pointer with the intention of mutating the object.
The caller must ensure, that this pointer is not used after self
’s
destruction.
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.