Created
March 14, 2018 04:23
-
-
Save inv2004/75ed1d8dc8336dbe23e8e7bd362c5022 to your computer and use it in GitHub Desktop.
test soa lifetimes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] extern crate soa_derive; | |
// lib | |
trait MyTrait:Sized { | |
type V; | |
type S; | |
fn new() -> Pl<Self::V>; | |
fn new_slice(s: Self::S) -> Pl<Self::S>; | |
fn test(&self) -> f32; | |
} | |
struct Pl<T>(T); | |
impl<'a,T> Pl<T> where | |
&'a T:IntoIterator, | |
T: 'a, | |
<&'a T as IntoIterator>::Item: MyTrait, | |
{ | |
fn each(&'a self) { | |
self.0.into_iter().for_each(|x| println!("result: {}", x.test())); | |
} | |
} | |
// bin | |
#[derive(Debug, StructOfArray)] | |
pub struct S { | |
a: f32, | |
b: f32 | |
} | |
impl<'a> MyTrait for SRef<'a> { | |
type V = SVec; | |
type S = SSlice<'a>; | |
fn new() -> Pl<Self::V> { | |
Pl(SVec{ | |
a:vec![1.1,2.2,3.3], | |
b:vec![1.0,2.0,3.0], | |
}) | |
} | |
fn new_slice(s: Self::S) -> Pl<Self::S> { | |
Pl(s) | |
} | |
fn test(&self) -> f32 { | |
self.a + self.a | |
} | |
} | |
fn main() { | |
let p = SRef::new(); | |
p.each(); | |
p.each(); | |
let a = vec![1.1,2.2]; | |
let b = vec![2.2,1.1]; | |
let ps = SRef::new_slice(SSlice{a:&a, b:&b}); | |
ps.each(); | |
ps.each(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment