From 86e33981c5f2647c600dc8186c6856c97df44fe8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 24 Jul 2021 01:12:20 +0100 Subject: [PATCH] wip resolve Signed-off-by: Ian Jackson --- src/config.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index bbcb730..34ce97d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -267,6 +267,15 @@ trait Parseable: Sized { fn parse(s: &Option) -> Result; } +impl Parseable for Duration { + #[throws(AE)] + fn parse(s: &Option) -> Duration { + let s = s.as_ref().ok_or_else(|| anyhow!("value needed"))?; + if let Ok(u64) = s.parse() { return Duration::from_secs(u64) } + throw!(anyhow!("xxx parse with humantime")) + } +} + impl<'c> ResolveContext<'c> { fn first_of_raw(&self, key: &'static str, sections: &[SectionName]) -> Option<&'c RawVal> { @@ -348,13 +357,14 @@ impl<'c> ResolveContext<'c> { } } -/* -fn resolve_instance_config() { - InstanceConfig { - max_batch_down: resolve::limited(&agg, "max_batch_down")?.into() +impl<'c> ResolveContext<'c> { + #[throws(AE)] + fn resolve_instance(&self) -> InstanceConfig { + InstanceConfig { + max_batch_down: self.limited::("max_batch_down")?.into(), + } } } -*/ #[throws(AE)] pub fn read() { -- 2.30.2