agg: &'c Aggregate,
link: &'c LinkName,
end: LinkEnd,
- lookup_ordinary: Vec<SectionName>,
- lookup_limit: Vec<SectionName>,
- lookup_server_sections_only: Vec<SectionName>,
+ all_sections: Vec<SectionName>,
}
trait Parseable: Sized {
} }
parseable_from_str!{u32}
+#[derive(Debug,Copy,Clone)]
+enum SectionKindList {
+ Ordinary,
+ Limited,
+ Limits,
+ ClientAgnostic,
+ ServerName,
+}
+use SectionKindList as SKL;
+
+impl SectionKindList {
+ fn contains(self, s: &SectionName) -> bool {
+ match self {
+ SKL::Ordinary => matches!(s, SN::Link(_)
+ | SN::Client(_)
+ | SN::Server(_)
+ | SN::Common),
+
+ SKL::Limits => matches!(s, SN::ServerLimit(_)
+ | SN::GlobalLimit),
+
+ SKL::ClientAgnostic => matches!(s, SN::Common
+ | SN::Server(_)),
+
+ SKL::Limited => SKL::Ordinary.contains(s)
+ | SKL::Limits .contains(s),
+
+ SKL::ServerName => matches!(s, SN::Common)
+ | matches!(s, SN::Server(ServerName(name))
+ if name == "SERVER"),
+ }
+ }
+}
+
impl<'c> ResolveContext<'c> {
- fn first_of_raw(&self, key: &'static str, sections: &[SectionName])
+ fn first_of_raw(&self, key: &'static str, sections: SectionKindList)
-> Option<&'c RawVal> {
- for section in sections {
+ for section in self.all_sections.iter()
+ .filter(|s| sections.contains(s))
+ {
if let Some(raw) = self.agg.sections
.get(section)
.and_then(|vars: &SectionMap| vars.get(key))
}
#[throws(AE)]
- fn first_of<T>(&self, key: &'static str, sections: &[SectionName])
+ fn first_of<T>(&self, key: &'static str, sections: SectionKindList)
-> Option<T>
where T: Parseable
{
pub fn ordinary<T>(&self, key: &'static str) -> T
where T: Parseable + Default
{
- self.first_of(key, &self.lookup_ordinary)?
+ self.first_of(key, SKL::Ordinary)?
.unwrap_or_default()
}
where T: Parseable + Default + Ord
{
let val = self.ordinary(key)?;
- if let Some(limit) = self.first_of(key, &self.lookup_limit)? {
+ if let Some(limit) = self.first_of(key, SKL::Limits)? {
min(val, limit)
} else {
val
match self.end {
LinkEnd::Client => self.ordinary(key)?,
LinkEnd::Server => {
- self.first_of(key, &self.lookup_server_sections_only)?
+ self.first_of(key, SKL::ClientAgnostic)?
.unwrap_or_default()
},
}
agg: &agg,
link: &link,
end: LinkEnd::Server,
- lookup_ordinary: vec![
+ all_sections: 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()),
- ],
};
}