}
pub use SectionName as SN;
-#[derive(Debug,Clone,Hash,Eq,PartialEq)]
-struct LinkName {
- server: ServerName,
- client: ClientName,
-}
-
#[derive(Debug,Clone)]
struct RawVal { val: Option<String>, loc: Arc<PathBuf> }
type SectionMap = HashMap<String, RawVal>;
end: LinkEnd,
}
+trait Parseable: Sized {
+ fn parse(s: &Option<String>) -> Result<Self, AE>;
+}
+
impl<'c> ResolveContext<'c> {
- fn first_of_raw(&self, key: &str,
+ fn first_of_raw(&self, key: &'static str,
sections: &[ &dyn Fn() -> SectionName ])
-> Option<&'c RawVal> {
for section in sections {
}
#[throws(AE)]
- fn first_of<T>(&self, key: &str,
+ fn first_of<T>(&self, key: &'static str,
sections: &[ &dyn Fn() -> SectionName ])
-> Option<T>
- where T: FromStr
+ where T: Parseable
{
match self.first_of_raw(key, sections) {
None => None,
Some(raw) => Some({
- raw.val.parse()
+ Parseable::parse(&raw.val)
.context(key)
- .context(r#"in section "{}""#, &raw.section)
+// .with_context(|| format!(r#"in section "{}""#, §ion))
.dcontext(&raw.loc)?
}),
}
}
- pub fn ordinary<T>(&self, key: &str) -> T where T: FromStr + Default {
+ #[throws(AE)]
+ pub fn ordinary<T>(&self, key: &'static str) -> T
+ where T: Parseable + Default
+ {
self.first_of(key, &[
- || SN::Link(self.link.clone()),
- || SN::Client(self.link.client.clone()),
- || SN::Server(self.link.server.clone()),
- || SN::Common,
+ &|| SN::Link(self.link.clone()),
+ &|| SN::Client(self.link.client.clone()),
+ &|| SN::Server(self.link.server.clone()),
+ &|| SN::Common,
])?
.unwrap_or_default()
}
- pub fn limited<T>(&self, key: &str) -> T
- where T: FromStr + Default + PartialOrd
+ #[throws(AE)]
+ pub fn limited<T>(&self, key: &'static str) -> T
+ where T: Parseable + Default + Ord
{
- let val = self.ordinary(key);
+ let val = self.ordinary(key)?;
if let Some(limit) = self.first_of(key, &[
- || SN::LimitServer(self.link.server.clone()),
- || SN::LimitGlobal,
+ &|| SN::ServerLimit(self.link.server.clone()),
+ &|| SN::GlobalLimit,
])? {
- val = min(val, limit)
+ min(val, limit)
+ } else {
+ val
}
- val
}
- pub fn client<T>(&self, key: &str) -> T where T: FromStr + Default {
+ #[throws(AE)]
+ pub fn client<T>(&self, key: &'static str) -> T
+ where T: Parseable + Default {
match self.end {
LinkEnd::Client => self.ordinary(key)?,
LinkEnd::Server => default(),
}
}
- pub fn server<T>(&self, key: &str) -> T where T: FromStr + Default {
+ #[throws(AE)]
+ pub fn server<T>(&self, key: &'static str) -> T
+ where T: Parseable + Default {
match self.end {
LinkEnd::Server => self.ordinary(key)?,
LinkEnd::Client => default(),
}
}
- pub fn special_ipif<T>(&self, key: &str) -> T where T: FromStr + Default {
+ #[throws(AE)]
+ pub fn special_ipif<T>(&self, key: &'static str) -> T
+ where T: Parseable + Default
+ {
match self.end {
LinkEnd::Client => self.ordinary(key)?,
LinkEnd::Server => {
self.first_of(key, &[
- || SN::Common,
- || SN::Server(self.link.server.clone()),
+ &|| SN::Common,
+ &|| SN::Server(self.link.server.clone()),
])?
+ .unwrap_or_default()
},
}
}
/*
fn resolve_instance_config() {
InstanceConfig {
- max_batch_down: resolve::limited(&agg, "max_batch_down")
+ max_batch_down: resolve::limited(&agg, "max_batch_down")?.into()
}
}
*/