chiark / gitweb /
wip resolve
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 24 Jul 2021 00:12:20 +0000 (01:12 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 24 Jul 2021 00:12:20 +0000 (01:12 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/config.rs

index bbcb730f883486a8c448d10f948e5c76aaaddeae..34ce97de68008d2ef5719f32e200dd17e34c62cd 100644 (file)
@@ -267,6 +267,15 @@ trait Parseable: Sized {
   fn parse(s: &Option<String>) -> Result<Self, AE>;
 }
 
+impl Parseable for Duration {
+  #[throws(AE)]
+  fn parse(s: &Option<String>) -> 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::<u32>("max_batch_down")?.into(),
+    }
   }
 }
-*/
 
 #[throws(AE)]
 pub fn read() {