summaryrefslogtreecommitdiff
path: root/subplotlib-derive
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-05 11:45:56 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-21 08:39:33 +0000
commit2e841608a19fe781220863d1fcca6c4868ca4812 (patch)
treebe17bdb1c9733853451fd503f6a0d8b73a91d1f8 /subplotlib-derive
parenta1ffaea8703126af20f2a4a61fa53fea8c17e218 (diff)
downloadsubplot-2e841608a19fe781220863d1fcca6c4868ca4812.tar.gz
rust: Switch to a neater module based step function derive
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'subplotlib-derive')
-rw-r--r--subplotlib-derive/src/lib.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/subplotlib-derive/src/lib.rs b/subplotlib-derive/src/lib.rs
index 6570750..a92ab1c 100644
--- a/subplotlib-derive/src/lib.rs
+++ b/subplotlib-derive/src/lib.rs
@@ -184,11 +184,6 @@ fn process_step(input: ItemFn) -> proc_macro2::TokenStream {
})
.collect::<Result<Vec<_>, _>>()?;
- // The builder's name is simply the step function's name with BUILDER_
- // prepended to it. We give that name the span of the step function name
- // in case it gets referred to in an error
- let buildername = Ident::new(&format!("BUILDER_{}", stepname), stepname.span());
-
let structdef = {
let structfields: Vec<_> = fields
.iter()
@@ -207,7 +202,7 @@ fn process_step(input: ItemFn) -> proc_macro2::TokenStream {
#[allow(non_camel_case_types)]
#[allow(unused)]
#[derive(Default)]
- #vis struct #buildername {
+ pub(crate) struct Builder {
#(#structfields),*
}
}
@@ -263,7 +258,7 @@ fn process_step(input: ItemFn) -> proc_macro2::TokenStream {
};
quote! {
- impl #buildername {
+ impl Builder {
#(#fieldfns)*
pub fn build(self) -> ScenarioStep<#contexttype> {
@@ -275,12 +270,15 @@ fn process_step(input: ItemFn) -> proc_macro2::TokenStream {
};
let ret = quote! {
- #structdef
- #structimpl
+ #vis mod #stepname {
+ use super::*;
+ #structdef
+ #structimpl
- #[throws(StepError)]
- #[allow(unused)] // It's okay for step functions to not be used
- #input
+ #[throws(StepError)]
+ #[allow(unused)] // It's okay for step functions to not be used
+ #input
+ }
};
ret