#[derive(hippotat_macros::ResolveConfig)]
pub struct InstanceConfig {
-/*
// Exceptional settings
- #[special(special_name, SKL::ServerName)] pub server: String,
- pub secret: String, // xxx newytpe
- #[special(special_ipif, SKL::Ordinary)] pub ipif: String,
+ #[special(special_server, SKL::ServerName)] pub server: ServerName,
+ pub secret: String, //xxx newytpe
+ #[special(special_ipif, SKL::Ordinary)] pub ipif: String,
// Capped settings:
-*/
#[limited] pub max_batch_down: u32,
#[limited] pub max_queue_time: Duration,
#[limited] pub http_timeout: Duration,
}
static OUTSIDE_SECTION: &str = "[";
+static SPECIAL_SERVER_SECTION: &str = "SERVER";
#[derive(Default,Debug)]
struct Aggregate {
link: &'c LinkName,
end: LinkEnd,
all_sections: Vec<SectionName>,
+ special_server_section: SectionName,
}
trait Parseable: Sized {
}
use SectionKindList as SKL;
+impl SectionName {
+ fn special_server_section() -> Self { SN::Server(ServerName(
+ SPECIAL_SERVER_SECTION.into()
+ )) }
+}
+
impl SectionKindList {
fn contains(self, s: &SectionName) -> bool {
match self {
SKL::ServerName => matches!(s, SN::Common)
| matches!(s, SN::Server(ServerName(name))
- if name == "SERVER"),
+ if name == SPECIAL_SERVER_SECTION),
}
}
}
impl<'c> ResolveContext<'c> {
- fn first_of_raw(&self, key: &'static str, sections: SectionKindList)
- -> Option<&'c RawVal> {
- for section in self.all_sections.iter()
- .filter(|s| sections.contains(s))
- {
+ fn lookup_raw<'n, S>(&self, key: &'static str, sections: S)
+ -> Option<&'c RawVal>
+ where S: Iterator<Item=&'n SectionName>
+ {
+ for section in sections {
if let Some(raw) = self.agg.sections
.get(section)
.and_then(|vars: &SectionMap| vars.get(key))
None
}
+ fn first_of_raw(&self, key: &'static str, sections: SectionKindList)
+ -> Option<&'c RawVal> {
+ self.lookup_raw(
+ key,
+ self.all_sections.iter()
+ .filter(|s| sections.contains(s))
+ )
+ }
+
#[throws(AE)]
fn first_of<T>(&self, key: &'static str, sections: SectionKindList)
-> Option<T>
}
#[throws(AE)]
- pub fn special_ipif<T>(&self, key: &'static str) -> T
- where T: Parseable + Default
- {
+ pub fn special_ipif(&self, key: &'static str) -> String {
match self.end {
LinkEnd::Client => self.ordinary(key)?,
LinkEnd::Server => {
},
}
}
+
+ #[throws(AE)]
+ pub fn special_server(&self, key: &'static str) -> ServerName {
+ let raw = match self.lookup_raw(
+ "server",
+ [ &SectionName::Common, &self.special_server_section ].iter().cloned()
+ ) {
+ Some(RawVal { val: Some(ref got),.. }) => got,
+ Some(RawVal { val: None,.. }) => throw!(anyhow!("value needed")),
+ None => SPECIAL_SERVER_SECTION,
+ };
+ ServerName(raw.into())
+ }
}
/*
SN::ServerLimit(link.server.clone()),
SN::GlobalLimit,
],
+ special_server_section: SN::special_server_section(),
};
}