Skip to main content

Task

Trait Task 

Source
pub trait Task:
    Sized
    + Send
    + Sync
    + 'static {
    const TYPE: &'static str;
    const VERSION: u32 = 1;
    const ALIASES: &'static [&'static str] = _;

    // Required methods
    fn encode(&self) -> Result<Vec<u8>, CodecError>;
    fn decode(bytes: &[u8]) -> Result<Self, CodecError>;

    // Provided methods
    fn upcast(version: u32, bytes: &[u8]) -> Result<Self, CodecError> { ... }
    fn options() -> TaskOptions { ... }
}
Expand description

A unit of work. TYPE is wire state — changing it strands enqueued jobs.

Required Associated Constants§

Source

const TYPE: &'static str

Provided Associated Constants§

Source

const VERSION: u32 = 1

payload versioning Bump when the payload shape changes; implement upcast for the old one.

Source

const ALIASES: &'static [&'static str] = _

typed dispatch Kinds this worker also answers to. Enqueue always uses TYPE; dispatch matches TYPE or any alias. Without this, renaming a task strands every job of the old kind — the same failure payload versioning prevents, through a door payload versioning does not cover.

Required Methods§

Source

fn encode(&self) -> Result<Vec<u8>, CodecError>

Source

fn decode(bytes: &[u8]) -> Result<Self, CodecError>

Provided Methods§

Source

fn upcast(version: u32, bytes: &[u8]) -> Result<Self, CodecError>

Decode an older payload into the current shape. The default rejects anything but the current version, which sends the job to Undecodable rather than retrying a decode error 25 times.

Source

fn options() -> TaskOptions

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§