Struct Task

Source
pub struct Task<T, E = Error> {
    pub f: fn(Event<'_, T>) -> Result<(), E>,
    pub hz: f32,
    pub max_time_micros: u16,
    pub is_high_priority: bool,
    pub last_run: u16,
}
Expand description

A task to run at specific frequency

Fields§

§f: fn(Event<'_, T>) -> Result<(), E>

The function to run.

§hz: f32

The desired frequency (in hz) to run the task.

§max_time_micros: u16

The max time for this task (in microseconds).

§is_high_priority: bool

Determines if this task should be run every time the scheduler loops.

§last_run: u16

The last tick this task was ran.

Implementations§

Source§

impl<T, E> Task<T, E>

Source

pub fn new(f: fn(Event<'_, T>) -> Result<(), E>) -> Self

Create a new task from the function to run.

Source

pub fn high_priority(f: fn(Event<'_, T>) -> Result<(), E>) -> Self

Create a new high priority task from the function to run.

Source

pub fn with_hz(self, hz: f32) -> Self

Builder method to set hz and return self

Source

pub fn with_max_time(self, micros: u16) -> Self

Builder method to set max_time_micros and return self

Source

pub fn with_high_priority(self, is_high_priority: bool) -> Self

Builder method to set is_high_priority and return self

Source

pub fn ticks(&self, loop_rate_hz: i16) -> i16

Calculate the desired ticks between each run of the task

Source

pub fn ready(&self, current_tick: u16, ticks: i16) -> Option<u16>

If this task is ready returns the ticks elapsed since the last run. Otherwise this returns None.

Source

pub fn run(&mut self, state: Event<'_, T>, tick: u16) -> Result<(), E>

Run this task at the current tick.

Auto Trait Implementations§

§

impl<T, E> Freeze for Task<T, E>

§

impl<T, E> RefUnwindSafe for Task<T, E>

§

impl<T, E> Send for Task<T, E>

§

impl<T, E> Sync for Task<T, E>

§

impl<T, E> Unpin for Task<T, E>

§

impl<T, E> UnwindSafe for Task<T, E>

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, 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.