pub struct RawExtension<S, T = ()>where
S: ExtensionSide,{ /* private fields */ }Expand description
A raw extension pointer.
This type is used by extension implementations to abstract away most of the safety concerns of using extension pointers.
Using the S type parameter with either PluginExtensionSide or HostExtensionSide, this
can be used as either a plugin-side extension or a host-side extension, respectively.
The T type parameter is the extension struct this points to (e.g. clap_plugin_state), or
() if the extension pointer is untyped.
Internally, this holds two pointers: a pointer to the actual extension struct, and a pointer
to the matching clap_plugin or clap_host. These are compared on each use to make sure
that the right extensions are always called with the right instance.
This type does not directly track the lifetimes of its pointers at all, they may become dangling
at any time. However, it is part of the safety contract of this type that the extension pointer
MUST be valid as long as the matching clap_plugin or clap_host still is, as per the CLAP
specification.
This property is then extrapolated so that if any valid clap_plugin or clap_host reference,
that also matches the pointer stored in this type, is encountered, then it must mean that the
inner extension pointer is also valid, and can be safely de-referenced.
To safely get valid references to the extension struct out of this type, you have to use the
use_extension() method on one of the handle types:
- For plugin-side extensions (from the
clack-hostcrate):PluginSharedHandle,PluginMainThreadHandle, orPluginAudioProcessorHandle; - For host-side extensions (from the
clack-plugincrate):HostSharedHandle,HostMainThreadHandle, orHostAudioProcessorHandle.
This pointer type is only useful for consuming extension pointers. For producing extension
pointers from an extension implementation, use the RawExtensionImplementation type instead.
Implementations§
Source§impl<S, T> RawExtension<S, T>where
S: ExtensionSide,
impl<S, T> RawExtension<S, T>where
S: ExtensionSide,
Sourcepub const fn as_ptr(&self) -> NonNull<T>
pub const fn as_ptr(&self) -> NonNull<T>
Returns the raw pointer to the extension struct.
This pointer may be dangling at any time.
See the RawExtension type documentation for more information on how to get a valid
reference to the extension struct instead.
Source§impl<S> RawExtension<S>where
S: ExtensionSide,
impl<S> RawExtension<S>where
S: ExtensionSide,
Sourcepub const unsafe fn cast<T>(&self) -> RawExtension<S, T>
pub const unsafe fn cast<T>(&self) -> RawExtension<S, T>
Casts this raw extension pointer into an extension pointer of a given type.
§Safety
Users must ensure that T matches the actual type behind the pointer.
Source§impl<T> RawExtension<PluginExtensionSide, T>
impl<T> RawExtension<PluginExtensionSide, T>
Sourcepub const unsafe fn from_raw_plugin_extension(
extension_ptr: NonNull<T>,
plugin_ptr: NonNull<clap_plugin>,
) -> RawExtension<PluginExtensionSide, T>
pub const unsafe fn from_raw_plugin_extension( extension_ptr: NonNull<T>, plugin_ptr: NonNull<clap_plugin>, ) -> RawExtension<PluginExtensionSide, T>
Creates a raw plugin-side extension pointer from a pointer to the extension data, and a pointer to the plugin instance.
§Safety
The user must ensure the extension_ptr is and remains valid for the lifetime of the
plugin instance.
This is the case for pointers received from the raw clap_plugin.get_extension method.
The given plugin_ptr however doesn’t have to be valid, and may be dangling.
Sourcepub const fn plugin_ptr(&self) -> NonNull<clap_plugin>
pub const fn plugin_ptr(&self) -> NonNull<clap_plugin>
Returns the raw pointer to the plugin instance the extension originated from.
This pointer may be dangling at any time, and is not meant to be de-referenced, only
compared to.
See the RawExtension type documentation for more information.
Source§impl<T> RawExtension<HostExtensionSide, T>
impl<T> RawExtension<HostExtensionSide, T>
Sourcepub const unsafe fn from_raw_host_extension(
extension_ptr: NonNull<T>,
host_ptr: NonNull<clap_host>,
) -> RawExtension<HostExtensionSide, T>
pub const unsafe fn from_raw_host_extension( extension_ptr: NonNull<T>, host_ptr: NonNull<clap_host>, ) -> RawExtension<HostExtensionSide, T>
Creates a raw host-side extension pointer from a pointer to the extension data, and a pointer to the plugin instance.
§Safety
The user must ensure the extension_ptr is and remains valid for the lifetime of the
plugin instance.
This is the case for pointers received from the raw clap_host.get_extension method.
The given host_ptr however doesn’t have to be valid, and may be dangling.
Sourcepub const fn host_ptr(&self) -> NonNull<clap_host>
pub const fn host_ptr(&self) -> NonNull<clap_host>
Returns the raw pointer to the host instance the extension originated from.
This pointer may be dangling at any time, and is not meant to be de-referenced, only
compared to.
See the RawExtension type documentation for more information.
Trait Implementations§
Source§impl<S, T> Clone for RawExtension<S, T>
impl<S, T> Clone for RawExtension<S, T>
Source§fn clone(&self) -> RawExtension<S, T>
fn clone(&self) -> RawExtension<S, T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more