Hi I am playing around with a design mainly as a learning exercise where I can string some elements together and each one does a little manipulation on some data before the next to allowed to do it's processing.
I have a simple test case though that I can't get going.
The errors are
92 | thread::spawn(move || {
| ^^^^^^^^^^^^^ the trait std::marker::Sync
is not implemented for element::Element
The code is below.
Not sure why this is as the tuple of (Box, Arc) should be able to be passed across thread I believe. Although must be wrong.
How could I call the run method in each of the elements in the vector in a different thread ?
Thanks.
type PipelineResult<T> = Result<T, PipeLineError>;
type PipeLineStreamFormat = (String, String);
pub trait Element {
fn run(&self, position : Arc<AtomicUsize>);
}
pub struct TestElement{
}
impl TestElement {
pub fn new() -> Self {
TestElement{
}
}
}
impl Element for TestElement {
fn run(&self, position : Arc<AtomicUsize>) {
loop {
println!("Hello");
}
}
}
pub struct Pipeline {
elements : Vec<(Box<Element>, Arc<AtomicUsize>)>,
data_queue : Vec<PipeLineStreamFormat>,
}
impl Pipeline {
pub fn new(name: String) -> Self {
Pipeline{
elements : Vec::new(),
data_queue : Vec::new(),
}
}
pub fn add_element(&mut self, element: Box<Element>) -> PipelineResult<()> {
self.elements.push((element, Arc::new(AtomicUsize::new(0))));
Ok(())
}
pub fn run(&self) {
loop {
let e = &self.elements[0];
thread::spawn(move || {
e.0.run(e.1);
});
}
}
fn main() {
let mut pipeline = Pipeline::new("example pipeline".to_string());
let e1 = TestElement::new();
pipeline.add_element(Box::new(e1)).unwrap();
pipeline.run();
}