From: Ian Jackson Date: Sat, 7 Aug 2021 21:15:32 +0000 (+0100) Subject: config: allow `special` to override, and set global for ipif X-Git-Tag: hippotat/1.0.0~254 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=65906614eaf4c771939d7b62b6396974e392ee7c;p=hippotat.git config: allow `special` to override, and set global for ipif Signed-off-by: Ian Jackson --- diff --git a/macros/macros.rs b/macros/macros.rs index 771448e..43efcf6 100644 --- a/macros/macros.rs +++ b/macros/macros.rs @@ -7,6 +7,8 @@ use syn::{Data, DataStruct, DeriveInput, LitStr, Meta, NestedMeta}; use quote::{quote, quote_spanned, ToTokens}; use proc_macro2::{Literal, TokenStream}; +use std::cell::RefCell; + use itertools::Itertools; /// Generates config resolver method @@ -64,11 +66,12 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { //dbg!(field); let fname = &field.ident.as_ref().unwrap(); let fname_span = fname.span(); - let mut skl = None; - let mut set_skl = |new| { - if let Some(old) = &skl { panic!("dup SKL {} and {} for field {}", - old, new, &fname); } - skl = Some(new); + let skl = RefCell::new(None); + let set_skl = |new| { + let mut skl = skl.borrow_mut(); + if let Some(old) = &*skl { panic!("dup SKL {} and {} for field {}", + old, new, &fname); } + *skl = Some(new); }; let mut method = quote_spanned!{fname_span=> ordinary }; for attr in &field.attrs { @@ -102,12 +105,13 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { } } method = get_path(tmethod); - set_skl(get_path(tskl)); + *skl.borrow_mut() = Some(get_path(tskl)); } } let fname_string = fname.to_string(); let fname_lit = Literal::string( &fname_string ); - let skl = skl.expect(&format!("SKL not specified! (field {})!", fname)); + let skl = skl.into_inner() + .expect(&format!("SKL not specified! (field {})!", fname)); names.push(quote!{ (#fname_lit, #skl), diff --git a/src/bin/server.rs b/src/bin/server.rs index 20da0dd..72fc2dc 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -19,5 +19,7 @@ async fn main() { let ics = config::startup("hippotatd", LinkEnd::Server, &opts.config, &opts.log); + + dbg!(ics); } diff --git a/src/config.rs b/src/config.rs index bfb345e..98e5a1e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,7 +10,7 @@ pub struct InstanceConfig { // Exceptional settings #[special(special_link, SKL::None)] pub link: LinkName, #[per_client] pub secret: Secret, - #[special(special_ipif, SKL::PerClient)] pub ipif: String, + #[global] #[special(special_ipif, SKL::PerClient)] pub ipif: String, // Capped settings: #[limited] pub max_batch_down: u32, diff --git a/src/ini.rs b/src/ini.rs index 294bea3..20c3534 100644 --- a/src/ini.rs +++ b/src/ini.rs @@ -4,7 +4,6 @@ use crate::prelude::*; -use std::cell::{RefCell, RefMut}; use std::io::BufRead; use std::rc::Rc; diff --git a/src/prelude.rs b/src/prelude.rs index 5e4261d..1acbafd 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -6,6 +6,7 @@ pub use std::array; pub use std::collections::{BTreeSet, HashMap, VecDeque}; pub use std::convert::{TryFrom, TryInto}; pub use std::borrow::Cow; +pub use std::cell::{RefCell, RefMut}; pub use std::cmp::{min, max}; pub use std::fs; pub use std::fmt::{self, Debug, Display, Write as _};