From 846d6539ab3c9eb49b054ba1606b8f2beb9c5d23 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 24 Jul 2021 12:32:44 +0100 Subject: [PATCH] config, wip macro, generetes some code Signed-off-by: Ian Jackson --- macros/macros.rs | 18 +++++++++++++++++- src/config.rs | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/macros/macros.rs b/macros/macros.rs index 142a0f7..6431471 100644 --- a/macros/macros.rs +++ b/macros/macros.rs @@ -33,7 +33,7 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { ) .collect_vec(); -// let mut output = vec![]; + let mut output = vec![]; for field in &fields.named { dbg!(field); let mut skl = quote!{ SKL::Ordinary }; @@ -61,13 +61,29 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { skl = get_path(tskl); } } + let fname = &field.ident; + let fname_string = fname.as_ref().unwrap().to_string(); + let fname_lit = Literal::string( &fname_string ); + + output.push(quote!{ + #fname: rctx. #method ( #fname_lit )?, + }); eprintln!("{:?} method={:?} skl={:?}", field.ident, method, skl); } let output = quote! { impl #target { const FIELDS: &'static [&'static str] = &[ #( #names ),* ]; + + fn resolve_instance(rctx: &ResolveContext) + -> ::std::result::Result<#target, anyhow::Error> + { + ::std::result::Result::Ok(#target { + #( #output )* + }) + } } }; + eprintln!("{}", &output); output.into() } diff --git a/src/config.rs b/src/config.rs index 93693b1..e7b7783 100644 --- a/src/config.rs +++ b/src/config.rs @@ -25,13 +25,16 @@ pub struct CidrString(pub String); #[derive(hippotat_macros::ResolveConfig)] pub struct InstanceConfig { +/* // Exceptional settings #[special(special_name, SKL::ServerName)] pub server: String, pub secret: String, // xxx newytpe #[special(special_ipif, SKL::Ordinary)] pub ipif: String, // Capped settings: +*/ #[limited] pub max_batch_down: u32, +/* #[limited] pub max_queue_time: Duration, #[limited] pub http_timeout: Duration, #[limited] pub target_requests_outstanding: u32, @@ -56,6 +59,7 @@ pub struct InstanceConfig { #[client] pub http_retry: Duration, #[client] pub url: Uri, #[client] pub vroutes: Vec, +*/ } #[derive(Debug,Clone,Hash,Eq,PartialEq)] -- 2.30.2