Skip to main content

RawExtension

Struct RawExtension 

Source
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-host crate): PluginSharedHandle, PluginMainThreadHandle, or PluginAudioProcessorHandle;
  • For host-side extensions (from the clack-plugin crate): HostSharedHandle, HostMainThreadHandle, or HostAudioProcessorHandle.

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,

Source

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,

Source

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>

Source

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.

Source

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>

Source

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.

Source

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>
where S: Clone + ExtensionSide, T: Clone,

Source§

fn clone(&self) -> RawExtension<S, T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S, T> Copy for RawExtension<S, T>
where S: Copy + ExtensionSide, T: Copy,

Source§

impl<S, T> Eq for RawExtension<S, T>
where S: Eq + ExtensionSide, T: Eq,

Source§

impl<S, T> Hash for RawExtension<S, T>
where S: Hash + ExtensionSide, T: Hash,

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<S, T> Ord for RawExtension<S, T>
where S: Ord + ExtensionSide, T: Ord,

Source§

fn cmp(&self, other: &RawExtension<S, T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<S, T> PartialEq for RawExtension<S, T>

Source§

fn eq(&self, other: &RawExtension<S, T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<S, T> PartialOrd for RawExtension<S, T>

Source§

fn partial_cmp(&self, other: &RawExtension<S, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<S, T> Send for RawExtension<S, T>
where S: ExtensionSide,

Source§

impl<S, T> StructuralPartialEq for RawExtension<S, T>

Source§

impl<S, T> Sync for RawExtension<S, T>
where S: ExtensionSide,

Auto Trait Implementations§

§

impl<S, T> Freeze for RawExtension<S, T>
where NonNull<T>: Freeze, PhantomData<fn() -> S>: Freeze,

§

impl<S, T> RefUnwindSafe for RawExtension<S, T>

§

impl<S, T> Unpin for RawExtension<S, T>
where NonNull<T>: Unpin, PhantomData<fn() -> S>: Unpin,

§

impl<S, T> UnsafeUnpin for RawExtension<S, T>

§

impl<S, T> UnwindSafe for RawExtension<S, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.