Skip to content

Instantly share code, notes, and snippets.

@bootandy
Last active October 29, 2019 09:21
Show Gist options
  • Save bootandy/468230baaec80d04fb3a9a9e885e3d5a to your computer and use it in GitHub Desktop.
Save bootandy/468230baaec80d04fb3a9a9e885e3d5a to your computer and use it in GitHub Desktop.
Figure out why this won't work in rust
use rayon::prelude::*;
use std::rc::Rc;
use std::sync::Arc;
use std::cell::RefCell;
use std::cell::RefCell;
#[macro_use]
extern crate rayon;
struct ResultOfCalc {
}
// This is the magic you need:
trait Marker : Send + Sync {
}
impl Marker for ResultOfCalc {
}
struct Sphere {
t: Arc<dyn Marker>
}
fn calc_pixel2(data : &&Sphere) -> i32{
2
}
fn main() -> std::io::Result<()> {
let r = ResultOfCalc{};
let h = Sphere{t: Arc::new(r) };
//let h = (Sphere{});
let mut data = vec![];
for i in 0..100 {
data.push( &h);
}
let sum: Vec<i32> = data
.par_iter()
.map(calc_pixel2)
.collect();
println!("{:?}", sum);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment