Enum interval_task::runner::TaskWithHandle

source ·
pub enum TaskWithHandle {
    TaskFnHanle(Box<dyn FnTaskWithHandle + Send + Sync>),
    TaskFnMutHanle(Box<dyn FnMutTaskWithHandle + Send + Sync>),
}

Variants§

§

TaskFnHanle(Box<dyn FnTaskWithHandle + Send + Sync>)

§

TaskFnMutHanle(Box<dyn FnMutTaskWithHandle + Send + Sync>)

Implementations§

source§

impl TaskWithHandle

source

pub fn new_fn_task( t: impl FnTaskWithHandle + Send + Sync + 'static, ) -> TaskWithHandle

source

pub fn new_fn_mut_task( t: impl FnMutTaskWithHandle + Send + Sync + 'static, ) -> TaskWithHandle

Examples found in repository?
examples/runner.rs (lines 56-59)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
fn internal_close_example() {
    use interval_task::runner::{self, InternalRunnerExt, TaskWithHandle};
    use std::time::{Duration, Instant};

    struct RunnerTask(u32, Instant);
    impl runner::FnMutTaskWithHandle for RunnerTask {
        fn call_mut(&mut self) -> bool {
            if self.0 == 119 {
                println!("{}", self.1.elapsed().as_secs_f64());
                true
            } else {
                if self.0 == 0 {
                    self.1 = Instant::now();
                }
                self.0 += 1;
                false
            }
        }
    }
    let mut runner = runner::new_internal_close_runner(Duration::from_micros(1_000_000 / 120));
    runner.set_task(TaskWithHandle::new_fn_mut_task(RunnerTask(
        0,
        Instant::now(),
    )));
    runner.start().unwrap();
    runner.join().unwrap();
}

Trait Implementations§

Auto Trait Implementations§

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

§

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

§

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.