From: Ian Jackson Date: Sat, 7 Aug 2021 17:33:34 +0000 (+0100) Subject: config: Introduce SKL::None, currently for `computed` X-Git-Tag: hippotat/1.0.0~273 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=6b70a0550f2a7fd29d5cc1f8454b3e5adf780eaf;p=hippotat.git config: Introduce SKL::None, currently for `computed` This isn't complete yet, because we need to use this in more places and also arrange not to treat these as "allowed but in the wrong section" but "not a known config key". Signed-off-by: Ian Jackson --- diff --git a/macros/macros.rs b/macros/macros.rs index 64501be..9d64c24 100644 --- a/macros/macros.rs +++ b/macros/macros.rs @@ -70,6 +70,8 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { method = attr.path.to_token_stream(); if &attr.path == &parse_quote!{ limited } { skl = quote_spanned!{atspan=> SectionKindList::Limited }; + } else if &attr.path == &parse_quote!{ computed } { + skl = quote_spanned!{atspan=> SectionKindList::None }; } } else if &attr.path == &parse_quote!{ special } { let meta = match attr.parse_meta().unwrap() { diff --git a/src/config.rs b/src/config.rs index 6a5e6bf..d771a10 100644 --- a/src/config.rs +++ b/src/config.rs @@ -521,6 +521,7 @@ enum SectionKindList { Limits, Global, ServerName, + None, } use SectionKindList as SKL; @@ -550,6 +551,7 @@ impl SectionKindList { SKL::ServerName => matches!(s, SN::Common) | matches!(s, SN::Server(ServerName(name)) if name == SPECIAL_SERVER_SECTION), + SKL::None => false, } } } @@ -650,9 +652,10 @@ impl<'c> ResolveContext<'c> { } #[throws(AE)] - pub fn computed(&self, _key: &'static str, _skl: SKL) -> T + pub fn computed(&self, _key: &'static str, skl: SKL) -> T where T: Default { + assert_eq!(skl, SKL::None); default() }