From da1d3978425764a1b1f860e2a764680bb3bac452 Mon Sep 17 00:00:00 2001 From: Christophe Troestler Date: Sat, 30 Dec 2023 01:45:08 +0100 Subject: [PATCH] SharedSerial: do not hold a reference, just a lifetime dependency The type parameter also serves to distinguish the SharedSerial created from various sources. --- src/vector.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vector.rs b/src/vector.rs index e568779..e7fa2de 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -1,6 +1,6 @@ //! Vectors -use std::{mem, slice}; +use std::{mem, slice, marker::PhantomData}; use sundials_sys::*; use super::Context; @@ -55,8 +55,8 @@ pub unsafe trait Vector: Clone { /// Rust value. This is used internally to convert Rust values to /// appropriate input/outputs for Sundials routines. pub struct SharedSerial { - v: V, pub(crate) nv: N_Vector, + marker: PhantomData, // Lifetime of the Rust vector } impl Drop for SharedSerial { @@ -106,7 +106,7 @@ unsafe impl Vector for [f64; N] { N.try_into().unwrap(), self.as_ptr() as *mut _, ctx) }; - SharedSerial { v: self, nv } + SharedSerial { nv, marker: PhantomData } } type NVectorMut<'a> = SharedSerial<&'a mut [f64; N]>; @@ -119,7 +119,7 @@ unsafe impl Vector for [f64; N] { N.try_into().unwrap(), self.as_mut_ptr(), ctx) }; - SharedSerial { v: self, nv } + SharedSerial { nv, marker: PhantomData } } #[inline] @@ -188,7 +188,7 @@ where V: AsVector { self.len().try_into().unwrap(), self.as_ref().as_ptr() as *mut _, ctx) }; - SharedSerial {v: self, nv } + SharedSerial { nv, marker: PhantomData } } type NVectorMut<'a> = SharedSerial<&'a mut V>; @@ -202,7 +202,7 @@ where V: AsVector { self.len().try_into().unwrap(), self.as_mut().as_ptr() as *mut _, ctx) }; - SharedSerial {v: self, nv } + SharedSerial { nv, marker: PhantomData } } #[inline]