summaryrefslogtreecommitdiff
path: root/subplotlib
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-10 13:25:47 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-21 08:39:33 +0000
commit02575de1b29997dda61e7656700a4d61735a62da (patch)
treec962829688cdf8e75fa19e6e535e38498de76dbf /subplotlib
parent76b7d4eeb8c767186084d4fb51ff848ae89c7df1 (diff)
downloadsubplot-02575de1b29997dda61e7656700a4d61735a62da.tar.gz
subplotlib: Support direct calling of other steps
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'subplotlib')
-rw-r--r--subplotlib/helpers/subplotlib_impl.rs7
-rw-r--r--subplotlib/src/scenario.rs4
-rw-r--r--subplotlib/tests/subplotlib.rs7
3 files changed, 14 insertions, 4 deletions
diff --git a/subplotlib/helpers/subplotlib_impl.rs b/subplotlib/helpers/subplotlib_impl.rs
index 571dfd0..e0d8ad1 100644
--- a/subplotlib/helpers/subplotlib_impl.rs
+++ b/subplotlib/helpers/subplotlib_impl.rs
@@ -12,7 +12,7 @@ fn increment_counter(context: &mut Context) {
}
#[step]
-fn check_counter(context: &mut Context, num: usize) {
+fn internal_check_counter(context: &Context, num: usize) {
if context.counter != num {
throw!(format!(
"Counter was wrong, it was {} but {} was expected",
@@ -22,6 +22,11 @@ fn check_counter(context: &mut Context, num: usize) {
}
#[step]
+fn check_counter(context: &ScenarioContext, num: usize) {
+ internal_check_counter::call(context, num)?;
+}
+
+#[step]
fn acquire_file_content(context: &mut Context, somename: &str, file: SubplotDataFile) {
context.remember_file(somename, file);
}
diff --git a/subplotlib/src/scenario.rs b/subplotlib/src/scenario.rs
index d8bdd76..cf272f2 100644
--- a/subplotlib/src/scenario.rs
+++ b/subplotlib/src/scenario.rs
@@ -30,7 +30,7 @@ impl ScenarioContext {
/// With the extracted immutable context, run the function f.
pub fn with<C, F>(&self, func: F, permit_poison: bool) -> StepResult
where
- F: Fn(&C) -> StepResult,
+ F: FnOnce(&C) -> StepResult,
C: Default + Send + 'static,
{
self.with_mut(|c: &mut C| func(&*c), permit_poison)
@@ -39,7 +39,7 @@ impl ScenarioContext {
/// With the extracted mutable context, run the function f.
pub fn with_mut<C, F>(&self, func: F, permit_poison: bool) -> StepResult
where
- F: Fn(&mut C) -> StepResult,
+ F: FnOnce(&mut C) -> StepResult,
C: Default + Send + 'static,
{
let sci: &ScenarioContextItem<C> = if let Some(sci) = self.inner.try_get() {
diff --git a/subplotlib/tests/subplotlib.rs b/subplotlib/tests/subplotlib.rs
index f2a7921..84f66d6 100644
--- a/subplotlib/tests/subplotlib.rs
+++ b/subplotlib/tests/subplotlib.rs
@@ -44,7 +44,7 @@ fn increment_counter(context: &mut Context) {
}
#[step]
-fn check_counter(context: &mut Context, num: usize) {
+fn internal_check_counter(context: &Context, num: usize) {
if context.counter != num {
throw!(format!(
"Counter was wrong, it was {} but {} was expected",
@@ -54,6 +54,11 @@ fn check_counter(context: &mut Context, num: usize) {
}
#[step]
+fn check_counter(context: &ScenarioContext, num: usize) {
+ internal_check_counter::call(context, num)?;
+}
+
+#[step]
fn acquire_file_content(context: &mut Context, somename: &str, file: SubplotDataFile) {
context.remember_file(somename, file);
}