Struct synfx_dsp_jit::locked::LockedMutPtrs
source · [−]pub struct LockedMutPtrs<T, E>where
T: MutPointable<E>,{ /* private fields */ }
Expand description
This type locks up a Vec<> after creation and gives you a pointer to
a vector of mutable pointers: *const *mut T
.
It locks away the interior std::vec::Vec instances, so that they can’t be accidentally changed while you are messing around with the pointers.
See also LockedPtrs for a mutable alternative to this type.
The type T
must implement the MutPointable trait.
use synfx_dsp_jit::locked::*;
struct MyFFIStuff {
data: LockedMutPtrs<Vec<f64>, f64>,
}
let ffistuff = MyFFIStuff {
data: LockedMutPtrs::new(vec![vec![0.0; 10], vec![0.2; 30]]),
};
// We are guaranteed here, that the pointers here will not be
// invalidated until MyFFIStuff is dropped!
let pointers = ffistuff.data.pointers();
unsafe {
(*pointers[0]) = 10.0;
(*pointers[0].offset(1)) = 11.0;
(*pointers[1]) = 20.0;
};
Implementations
sourceimpl<T, E> LockedMutPtrs<T, E>where
T: MutPointable<E>,
impl<T, E> LockedMutPtrs<T, E>where
T: MutPointable<E>,
pub fn new(v: Vec<T>) -> Self
sourcepub unsafe fn swap_element(&mut self, idx: usize, elem: &mut T) -> Result<(), ()>
pub unsafe fn swap_element(&mut self, idx: usize, elem: &mut T) -> Result<(), ()>
Swaps out one element in the locked vector.
Safety
You must not call this function while you still have pointers handed out. These pointers will be invaldiated by this function!
pub fn len(&self) -> usize
pub fn element_len(&self, idx: usize) -> usize
pub fn lens(&self) -> &[u64]
pub fn pointers(&self) -> &[*mut E]
Auto Trait Implementations
impl<T, E> RefUnwindSafe for LockedMutPtrs<T, E>where
E: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, E> !Send for LockedMutPtrs<T, E>
impl<T, E> !Sync for LockedMutPtrs<T, E>
impl<T, E> Unpin for LockedMutPtrs<T, E>where
E: Unpin,
T: Unpin,
impl<T, E> UnwindSafe for LockedMutPtrs<T, E>where
E: UnwindSafe + RefUnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more