chiark / gitweb /
config, wip macro, generetes some code
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 24 Jul 2021 11:32:44 +0000 (12:32 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 24 Jul 2021 11:32:44 +0000 (12:32 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
macros/macros.rs
src/config.rs

index 142a0f7c3d0ef85541756e4025760be53229d04b..6431471dec25f9b4091dd1da5c746b2be7119348 100644 (file)
@@ -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()
 }
index 93693b1c4c32cdc9f5251a4cb79bb0006773d41a..e7b7783a0f5a1a76dfd94604b5fdb60a9fdbc60f 100644 (file)
@@ -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<CidrString>,
+*/
 }
 
 #[derive(Debug,Clone,Hash,Eq,PartialEq)]