#[derive(Debug)]
struct Aggregate {
+ end: LinkEnd,
keys_allowed: HashMap<&'static str, SectionKindList>,
sections: HashMap<SectionName, SectionMap>,
}
impl Aggregate {
fn new(
+ end: LinkEnd,
keys_allowed: HashMap<&'static str, SectionKindList>
) -> Self { Aggregate {
- keys_allowed,
+ end, keys_allowed,
sections: default(),
} }
|| anyhow!("unknown configuration key {:?}", key)
)?
};
- if ! skl.contains(&sn) {
+ if ! skl.contains(&sn, self.end) {
throw!(anyhow!("configuration key {:?} not applicable \
in this kind of section: {}", key, &sn))
}
}
impl SectionKindList {
- fn contains(self, s: &SectionName) -> bool {
- match self {
- SKL::PerClient => matches!(s, SN::Link(_)
+ fn contains(self, s: &SectionName, end: LinkEnd) -> bool {
+ match (self, end) {
+ (SKL::PerClient,_) => matches!(s, SN::Link(_)
| SN::Client(_)
| SN::Server(_)
| SN::Common),
- SKL::Limits => matches!(s, SN::ServerLimit(_)
+ (SKL::Limits,_) => matches!(s, SN::ServerLimit(_)
| SN::GlobalLimit),
- SKL::Global => matches!(s, SN::Common
- | SN::Server(_)),
+ (SKL::Global,_) => matches!(s, SN::Common
+ | SN::Server(_)),
- SKL::Limited => SKL::PerClient.contains(s)
- | SKL::Limits .contains(s),
+ (SKL::Limited,_) => SKL::PerClient.contains(s, end)
+ | SKL::Limits .contains(s, end),
- SKL::ServerName => matches!(s, SN::Common)
+ (SKL::ServerName,_) => matches!(s, SN::Common)
| matches!(s, SN::Server(ServerName(name))
if name == SPECIAL_SERVER_SECTION),
- SKL::None => false,
+ (SKL::None,_) => false,
}
}
}
self.agg.lookup_raw(
key,
self.all_sections.iter()
- .filter(|s| sections.contains(s))
+ .filter(|s| sections.contains(s, self.end))
)
}
pub fn read(opts: &Opts, end: LinkEnd) -> Vec<InstanceConfig> {
let agg = (||{
let mut agg = Aggregate::new(
+ end,
InstanceConfig::FIELDS.iter().cloned().collect(),
);