pub trait TypedTask:
Serialize
+ DeserializeOwned
+ Send
+ 'static {
const TASK_TYPE: &'static str;
// Provided methods
fn expected_read_bytes(&self) -> i64 { ... }
fn expected_write_bytes(&self) -> i64 { ... }
fn expected_net_rx_bytes(&self) -> i64 { ... }
fn expected_net_tx_bytes(&self) -> i64 { ... }
fn priority(&self) -> Priority { ... }
fn group_key(&self) -> Option<String> { ... }
}Expand description
A strongly-typed task that bundles serialization, task type name, and default IO estimates.
Implementing this trait collapses the 6 fields of TaskSubmission into a
derive-friendly pattern. Use Scheduler::submit_typed
to submit and TaskContext::payload on the
executor side to deserialize. Each TypedTask must have a corresponding
TaskExecutor registered under the same
TASK_TYPE name.
§Example
use serde::{Serialize, Deserialize};
use taskmill::{TypedTask, Priority};
#[derive(Serialize, Deserialize)]
struct Thumbnail { path: String, size: u32 }
impl TypedTask for Thumbnail {
const TASK_TYPE: &'static str = "thumbnail";
fn expected_read_bytes(&self) -> i64 { 4096 }
fn expected_write_bytes(&self) -> i64 { 1024 }
}Required Associated Constants§
Provided Methods§
Sourcefn expected_read_bytes(&self) -> i64
fn expected_read_bytes(&self) -> i64
Estimated bytes this task will read from disk. Default: 0.
Sourcefn expected_write_bytes(&self) -> i64
fn expected_write_bytes(&self) -> i64
Estimated bytes this task will write to disk. Default: 0.
Sourcefn expected_net_rx_bytes(&self) -> i64
fn expected_net_rx_bytes(&self) -> i64
Estimated bytes this task will receive over the network. Default: 0.
Sourcefn expected_net_tx_bytes(&self) -> i64
fn expected_net_tx_bytes(&self) -> i64
Estimated bytes this task will transmit over the network. Default: 0.
Sourcefn priority(&self) -> Priority
fn priority(&self) -> Priority
Scheduling priority. Default: Priority::NORMAL.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.