Skip to content

Commit 6d3924b

Browse files
committed
AsPtr helper trait to get pointer of slice
1 parent 328abd3 commit 6d3924b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lax/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,31 @@ impl Lapack for f64 {}
126126
impl Lapack for c32 {}
127127
impl Lapack for c64 {}
128128

129+
/// Helper for getting pointer of slice
130+
pub(crate) trait AsPtr: Sized {
131+
type Elem;
132+
fn as_ptr(vec: &[Self]) -> *const Self::Elem;
133+
fn as_mut_ptr(vec: &mut [Self]) -> *mut Self::Elem;
134+
}
135+
136+
macro_rules! impl_as_ptr {
137+
($target:ty, $elem:ty) => {
138+
impl AsPtr for $target {
139+
type Elem = $elem;
140+
fn as_ptr(vec: &[Self]) -> *const Self::Elem {
141+
vec.as_ptr() as *const _
142+
}
143+
fn as_mut_ptr(vec: &mut [Self]) -> *mut Self::Elem {
144+
vec.as_mut_ptr() as *mut _
145+
}
146+
}
147+
};
148+
}
149+
impl_as_ptr!(f32, f32);
150+
impl_as_ptr!(f64, f64);
151+
impl_as_ptr!(c32, lapack_sys::__BindgenComplex<f32>);
152+
impl_as_ptr!(c64, lapack_sys::__BindgenComplex<f64>);
153+
129154
/// Upper/Lower specification for seveal usages
130155
#[derive(Debug, Clone, Copy)]
131156
#[repr(u8)]

0 commit comments

Comments
 (0)