Struct synfx_dsp_jit::locked::LockedPtrs
source · [−]pub struct LockedPtrs<T, E>where
T: Pointable<E>,{ /* private fields */ }
Expand description
This type locks up a Vec<> after creation and gives you a pointer to
a vector of pointers: *const *const 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.
The type T
must implement the Pointable trait.
See also LockedMutPtrs for a mutable alternative to this type.
use synfx_dsp_jit::locked::*;
struct MyFFIStuff {
data: LockedPtrs<Vec<i64>, i64>,
}
let ffistuff = MyFFIStuff {
data: LockedPtrs::new(vec![vec![1; 10], vec![2; 30]]),
};
// We are guaranteed here, that the pointers here will not be
// invalidated until MyFFIStuff is dropped!
let pointers = ffistuff.data.pointers();
unsafe {
assert_eq!((*pointers[0]), 1);
assert_eq!((*pointers[1]), 2);
assert_eq!((*pointers[0].offset(5)), 1);
assert_eq!((*pointers[1].offset(5)), 2);
};
Implementations
sourceimpl<T, E> LockedPtrs<T, E>where
T: Pointable<E>,
impl<T, E> LockedPtrs<T, E>where
T: Pointable<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) -> &[*const E]
Auto Trait Implementations
impl<T, E> RefUnwindSafe for LockedPtrs<T, E>where
E: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, E> !Send for LockedPtrs<T, E>
impl<T, E> !Sync for LockedPtrs<T, E>
impl<T, E> Unpin for LockedPtrs<T, E>where
E: Unpin,
T: Unpin,
impl<T, E> UnwindSafe for LockedPtrs<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