pub trait WorkerJob: Copy + 'static {
type Input: WorkerData;
type Output: WorkerData;
const NAME: &'static str;
// Required method
fn run(input: Self::Input) -> Self::Output;
}Expand description
A function withBlocking runs off the UI thread on
every platform: on a pool thread where the platform has threads, in a Web
Worker in a browser. The #[worker_job] attribute implements it for a
function, and the function’s with makes the call withBlocking takes:
ⓘ
#[worker_job]
fn word_count(text: String) -> u32 {
text.split_whitespace().count() as u32
}
scope.launch(async move {
if let Ok(count) = withBlocking(word_count.with(text)).await {
shown.set(count);
}
});Required Associated Constants§
Required Associated Types§
Sourcetype Input: WorkerData
type Input: WorkerData
What the job takes.
Sourcetype Output: WorkerData
type Output: WorkerData
What the job returns.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".