pub trait Runnable: Send + 'static {
type Output: Send + 'static;
// Required method
fn run(self) -> Self::Output;
}Expand description
A trait for defining a task that can be executed, typically in a separate thread.
Types implementing Runnable must be Send and 'static to ensure they
can be safely transferred across thread boundaries. By encapsulating state
within a struct that implements this trait, you can easily manage complex
thread initialization.
§Examples
use struct_threads::Runnable;
struct GreetingTask {
name: String,
}
impl Runnable for GreetingTask {
type Output = String;
fn run(self) -> Self::Output {
format!("Hello, {}!", self.name)
}
}