Trait rust_runnables::Runnable [] [src]

pub trait Runnable {
    fn run(&mut self);
}

A Runnable is a single function trait with no return value

Examples

Simple runnable that does nothing:

use rust_runnables::Runnable;

struct MyRunnable;

impl Runnable for MyRunnable {
    fn run(&mut self) {}
}

Passing a Runnable to something that expects a function pointer:

fn call_a_function(the_function: &mut FnMut()) {
    the_function();
}

let mut my_runnable = MyRunnable;
call_a_function( &mut || my_runnable.run());

Or for a function that takes an immutable Fn():

use std::cell::RefCell;

fn call_a_function(the_function: &Fn()) {
    the_function();
}

let celled_runnable = RefCell::new(MyRunnable);
call_a_function( &|| celled_runnable.borrow_mut().run());

Required Methods

Implementors