Skip to content

Instantly share code, notes, and snippets.

@inv2004
Created March 14, 2018 04:23
Show Gist options
  • Save inv2004/75ed1d8dc8336dbe23e8e7bd362c5022 to your computer and use it in GitHub Desktop.
Save inv2004/75ed1d8dc8336dbe23e8e7bd362c5022 to your computer and use it in GitHub Desktop.
test soa lifetimes
#[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