pub struct SendPtr<T>(/* private fields */);Expand description
A raw pointer wrapper that is Send + Sync.
Used to capture *const Params / host-handle pointers in
PluginContext closures without the ptr as usize hack. The
Send/Sync impls are unconditional in T - they have to be,
because the wrapped types are typically #[repr(C)] host structs
that are themselves !Send + !Sync by default. Construction is
therefore unsafe: each call site must justify why cross-thread
access to the pointed-to data is sound.
Justifications used in-tree:
P: Params- fields are atomic; concurrent reads from the GUI thread while the audio thread writes are safe by design.- Format-host handles (
clap_host,AEffect, etc.) - used only from a single thread (UI), and the wrapping is purely for capturing inSend + Syncclosures stored inPluginContext.
The pointed-to data must outlive the SendPtr. In the plugin
context, the plugin instance (which owns the params) always
outlives the editor.
Implementations§
Source§impl<T> SendPtr<T>
impl<T> SendPtr<T>
Sourcepub unsafe fn new(ptr: *const T) -> Self
pub unsafe fn new(ptr: *const T) -> Self
Wrap a raw pointer.
§Safety
The caller must ensure that:
- The pointed-to data outlives every clone of this
SendPtr. - Cross-thread access to
*ptris sound - either becauseTisSync, because access is synchronized externally (atomic fields, Mutex, single-thread-only access pattern), or because the wrapper is only ever read on a thread whereT: Syncwould hold.
Trait Implementations§
impl<T> Copy for SendPtr<T>
impl<T> Send for SendPtr<T>
impl<T> Sync for SendPtr<T>
Auto Trait Implementations§
impl<T> Freeze for SendPtr<T>
impl<T> RefUnwindSafe for SendPtr<T>where
T: RefUnwindSafe,
impl<T> Unpin for SendPtr<T>
impl<T> UnsafeUnpin for SendPtr<T>
impl<T> UnwindSafe for SendPtr<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more