agg: &'c Aggregate,
link: &'c LinkName,
end: LinkEnd,
+ lookup_ordinary: Vec<SectionName>,
+ lookup_limit: Vec<SectionName>,
+ lookup_server_sections_only: Vec<SectionName>,
}
trait Parseable: Sized {
}
impl<'c> ResolveContext<'c> {
- fn first_of_raw(&self, key: &'static str,
- sections: &[ &dyn Fn() -> SectionName ])
+ fn first_of_raw(&self, key: &'static str, sections: &[SectionName])
-> Option<&'c RawVal> {
for section in sections {
if let Some(raw) = self.agg.sections
- .get(§ion())
+ .get(section)
.and_then(|vars: &SectionMap| vars.get(key))
{
return Some(raw)
}
#[throws(AE)]
- fn first_of<T>(&self, key: &'static str,
- sections: &[ &dyn Fn() -> SectionName ])
+ fn first_of<T>(&self, key: &'static str, sections: &[SectionName])
-> Option<T>
where T: Parseable
{
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,
- ])?
+ self.first_of(key, &self.lookup_ordinary)?
.unwrap_or_default()
}
where T: Parseable + Default + Ord
{
let val = self.ordinary(key)?;
- if let Some(limit) = self.first_of(key, &[
- &|| SN::ServerLimit(self.link.server.clone()),
- &|| SN::GlobalLimit,
- ])? {
+ if let Some(limit) = self.first_of(key, &self.lookup_limit)? {
min(val, limit)
} else {
val
match self.end {
LinkEnd::Client => self.ordinary(key)?,
LinkEnd::Server => {
- self.first_of(key, &[
- &|| SN::Common,
- &|| SN::Server(self.link.server.clone()),
- ])?
+ self.first_of(key, &self.lookup_server_sections_only)?
.unwrap_or_default()
},
}
pub fn read() {
let opts = config::Opts::from_args();
- (||{
+ let agg = (||{
let mut agg = Aggregate::default();
agg.read_toplevel(&opts.config)?;
eprintln!("GOT {:#?}", agg);
- Ok::<_,AE>(())
+ Ok::<_,AE>(agg)
})().context("read configuration")?;
+
+ let link = LinkName {
+ server: "fooxxx".parse().unwrap(),
+ client: "127.0.0.1".parse().unwrap(),
+ };
+
+ let rctx = ResolveContext {
+ agg: &agg,
+ link: &link,
+ end: LinkEnd::Server,
+ lookup_ordinary: vec![
+ SN::Link(link.clone()),
+ SN::Client(link.client.clone()),
+ SN::Server(link.server.clone()),
+ SN::Common,
+ ],
+ lookup_limit: vec![
+ SN::ServerLimit(link.server.clone()),
+ SN::GlobalLimit,
+ ],
+ lookup_server_sections_only: vec![
+ SN::Common,
+ SN::Server(link.server.clone()),
+ ],
+ };
}