pub struct CrossThreadTask { /* private fields */ }Expand description
A task sent from a background thread to the window thread.
Must be Send because it crosses thread boundaries.
Carries a priority so the scheduler can route it to the correct queue.
§Example
ⓘ
// On background thread:
let data = reqwest::get(url).await?;
// Send result back to window thread at Normal priority:
sender.send(CrossThreadTask::new(TaskPriority::Normal, move || {
btn.set_text(&data.title); // safe! runs on window thread
}));Implementations§
Source§impl CrossThreadTask
impl CrossThreadTask
Sourcepub fn new(
priority: TaskPriority,
callback: impl FnOnce() + Send + 'static,
) -> Self
pub fn new( priority: TaskPriority, callback: impl FnOnce() + Send + 'static, ) -> Self
Create a new cross-thread task with the given priority.
Sourcepub fn priority(&self) -> TaskPriority
pub fn priority(&self) -> TaskPriority
The priority this task should be routed to.
Auto Trait Implementations§
impl Freeze for CrossThreadTask
impl !RefUnwindSafe for CrossThreadTask
impl Send for CrossThreadTask
impl !Sync for CrossThreadTask
impl Unpin for CrossThreadTask
impl UnsafeUnpin for CrossThreadTask
impl !UnwindSafe for CrossThreadTask
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more