-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bump version * Add dev deps * Fix badge * Split into modules * Clean up README and doc comment * Job unit tests
- Loading branch information
1 parent
83bc28a
commit a3f92d3
Showing
8 changed files
with
991 additions
and
700 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! The work functions that can be scheduled must implement the `Callable` trait. | ||
|
||
use std::fmt; | ||
|
||
/// A job is anything that implements this trait | ||
pub(crate) trait Callable: fmt::Debug { | ||
/// Execute this callable | ||
fn call(&self) -> Option<bool>; | ||
/// Get the name of this callable | ||
fn name(&self) -> &str; | ||
} | ||
|
||
impl PartialEq for dyn Callable { | ||
fn eq(&self, other: &Self) -> bool { | ||
// Callable objects are equal if their names are equal | ||
// FIXME: this seems fishy | ||
self.name() == other.name() | ||
} | ||
} | ||
|
||
impl Eq for dyn Callable {} | ||
|
||
/// A named callable function taking no parameters and returning nothing. | ||
#[derive(Debug)] | ||
pub struct UnitToUnit { | ||
name: String, | ||
work: fn() -> (), | ||
} | ||
|
||
impl UnitToUnit { | ||
pub fn new(name: &str, work: fn() -> ()) -> Self { | ||
Self { | ||
name: name.into(), | ||
work, | ||
} | ||
} | ||
} | ||
|
||
impl Callable for UnitToUnit { | ||
fn call(&self) -> Option<bool> { | ||
(self.work)(); | ||
None | ||
} | ||
fn name(&self) -> &str { | ||
&self.name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.