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§

source§

impl<T, E> LockedMutPtrs<T, E>
where T: MutPointable<E>,

source

pub fn new(v: Vec<T>) -> Self

source

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!

source

pub fn len(&self) -> usize

source

pub fn element_len(&self, idx: usize) -> usize

source

pub fn lens(&self) -> &[u64]

source

pub fn pointers(&self) -> &[*mut E]

Auto Trait Implementations§

§

impl<T, E> RefUnwindSafe for LockedMutPtrs<T, E>

§

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>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.