silx_types/types/nalgebra/
froms.rs1use std::{ pin::Pin, ops::Deref, marker::PhantomData, };
2use rkyv::{Archive, Archived, };
3use nalgebra::{ Matrix, Const, };
4use super::{
5 ConstSlx, DerefMatrixSlx, ArrayStorageSlx, ArchRefArrayStorageSlx, ArchMutArrayStorageSlx,
6};
7
8impl<'a, T, const R: usize, const C: usize> From<&'a Archived<ArrayStorageSlx<T,R,C>>> for ArchRefArrayStorageSlx<'a, T,R,C> where T: Archive {
10 fn from(archived: &'a Archived<ArrayStorageSlx<T,R,C>>) -> Self { Self::new(archived) }
11}
12
13impl<'a, T, const R: usize, const C: usize> From<&'a mut Archived<ArrayStorageSlx<T,R,C>>> for ArchMutArrayStorageSlx<'a,T,R,C> where T: Archive {
15 fn from(archived: &'a mut Archived<ArrayStorageSlx<T,R,C>>) -> Self { Self::new(archived) }
16}
17
18impl<T,const R: usize,const C:usize> From<&ArrayStorageSlx<Archived<T>,R,C>>
20 for &Matrix<T,Const<R>,Const<C>,ArrayStorageSlx<Archived<T>,R,C>> where T: Archive {
21 fn from(data: &ArrayStorageSlx<Archived<T>,R,C>) -> Self {
22 unsafe{ std::mem::transmute(data) }
23 }
24}
25impl<T,const R: usize,const C:usize> From<Pin<&mut ArrayStorageSlx<Archived<T>,R,C>>>
26 for Pin<&mut Matrix<T,Const<R>,Const<C>,ArrayStorageSlx<Archived<T>,R,C>>> where T: Archive {
27 fn from(data: Pin<&mut ArrayStorageSlx<Archived<T>,R,C>>) -> Self {
28 unsafe{ std::mem::transmute(data) }
29 }
30}
31
32impl<'a, T,const R: usize,const C: usize> From<&'a Archived<ArrayStorageSlx<T,R,C>>>
34 for DerefMatrixSlx<T,ConstSlx<R>,ConstSlx<C>,ArchRefArrayStorageSlx<'a, T,R,C>> where T: Archive {
35 fn from(archived: &'a Archived<ArrayStorageSlx<T,R,C>>) -> Self {
36 let data = ArchRefArrayStorageSlx::new(archived); Self { data, _phantoms: PhantomData }
37 }
38}
39impl<'a, T,const R: usize,const C: usize> From<&'a mut Archived<ArrayStorageSlx<T,R,C>>>
41 for DerefMatrixSlx<T,ConstSlx<R>,ConstSlx<C>,ArchMutArrayStorageSlx<'a,T,R,C>> where T: Archive {
42 fn from(archived: &'a mut Archived<ArrayStorageSlx<T,R,C>>) -> Self {
43 let data = ArchMutArrayStorageSlx::new(archived); Self { data, _phantoms: PhantomData }
44 }
45}
46impl<'a, T,const R: usize,const C: usize> From<Pin<&'a mut Archived<ArrayStorageSlx<T,R,C>>>>
48 for Pin<DerefMatrixSlx<T,ConstSlx<R>,ConstSlx<C>,ArchMutArrayStorageSlx<'a,T,R,C>>>
49 where T: Archive + Unpin, DerefMatrixSlx<T,ConstSlx<R>,ConstSlx<C>,ArchMutArrayStorageSlx<'a,T,R,C>>: Deref,
50 <DerefMatrixSlx<T,ConstSlx<R>,ConstSlx<C>,ArchMutArrayStorageSlx<'a,T,R,C>> as Deref>::Target: Unpin, Archived<ArrayStorageSlx<T,R,C>>: Unpin, {
51 fn from(archived: Pin<&'a mut Archived<ArrayStorageSlx<T,R,C>>>) -> Self {
52 let archived = archived.get_mut();
53 let mat = From::from(archived);
54 Pin::new(mat)
55 }
56}
57