Skip to main content

Tasks

Struct Tasks 

Source
pub struct Tasks { /* private fields */ }
Expand description

Task set.

This data type represents a set of tasks that can either be consumed through iteration, or executed recursively via Tasks::execute. Anything returned by Task::execute must be convertible into Tasks, including a single task, multiple tasks, and the unit value.

§Examples

use zrx_executor::task::Tasks;
use zrx_executor::Executor;

// Create executor and submit task
let executor = Executor::default();
executor.submit(|| {
    println!("Task 1");

    // Create subtasks
    let mut tasks = Tasks::new();
    tasks.add(|| println!("Task 1.1"));
    tasks.add(|| println!("Task 1.2"));
    tasks.add(|| println!("Task 1.3"));
    tasks
})?;

Implementations§

Source§

impl Tasks

Source

pub fn new() -> Self

Creates a task set.

§Examples
use zrx_executor::task::Tasks;

// Create task set
let tasks = Tasks::new();
Source

pub fn add<T>(&mut self, task: T) -> &mut Self
where T: Task,

Adds a task to the task set.

This method adds a Task to the set, which can either be consumed via Tasks::into_iter or executed via Tasks::execute.

§Examples
use zrx_executor::task::Tasks;

// Create task set and add tasks
let mut tasks = Tasks::new();
tasks.add(|| println!("Task 1"));
tasks.add(|| println!("Task 2"));
tasks.add(|| println!("Task 3"));
Source

pub fn execute(self)

Executes all tasks in the task set.

This method executes all tasks recursively in depth-first order, so if a task returns further subtasks, they are executed before all others.

§Examples
use zrx_executor::task::Tasks;

// Create task set and add tasks
let mut tasks = Tasks::new();
tasks.add(|| println!("Task 1"));
tasks.add(|| println!("Task 2"));
tasks.add(|| println!("Task 3"));

// Execute task set
tasks.execute();
Source§

impl Tasks

Source

pub fn len(&self) -> usize

Returns the number of tasks.

Source

pub fn is_empty(&self) -> bool

Returns whether there are any tasks.

Trait Implementations§

Source§

impl Debug for Tasks

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tasks

Source§

fn default() -> Tasks

Returns the “default value” for a type. Read more
Source§

impl From<()> for Tasks

Source§

fn from((): ()) -> Self

Creates a task set from the unit value.

This implementation makes the API more flexible, as it allows to just return nothing from a task, which is probably the common case.

§Examples
use zrx_executor::task::Tasks;

// Create task set from unit value
let tasks = Tasks::from(());
assert!(tasks.is_empty());
Source§

impl<T> From<T> for Tasks
where T: Task,

Source§

fn from(task: T) -> Self

Creates a task set from a task.

This implementation creates a task set from a single task, which allows to conveniently return a single closure from a task.

§Examples
use zrx_executor::task::Tasks;

// Create task set from task
let tasks = Tasks::from(|| println!("Task"));
assert_eq!(tasks.len(), 1);
Source§

impl<I> FromIterator<I> for Tasks
where I: Task,

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = I>,

Creates a task set from an iterator.

§Examples
use zrx_executor::task::Tasks;

// Create task set from iterator
let tasks = Tasks::from_iter([
    || println!("Task 1"),
    || println!("Task 2"),
    || println!("Task 3"),
]);
Source§

impl IntoIterator for Tasks

Source§

fn into_iter(self) -> Self::IntoIter

Creates a consuming iterator over the task set.

§Examples
use zrx_executor::task::Tasks;

// Create task set and add tasks
let mut tasks = Tasks::new();
tasks.add(|| println!("Task 1"));
tasks.add(|| println!("Task 2"));
tasks.add(|| println!("Task 3"));

// Create iterator over tasks
for task in tasks {
    task.execute();
}
Source§

type Item = Box<dyn Task>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Tasks as IntoIterator>::Item>

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

impl Freeze for Tasks

§

impl !RefUnwindSafe for Tasks

§

impl Send for Tasks

§

impl !Sync for Tasks

§

impl Unpin for Tasks

§

impl UnsafeUnpin for Tasks

§

impl UnwindSafe for Tasks

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.