use announce macro instead of having to hardcode

This commit is contained in:
Noa Aarts 2024-12-10 17:22:31 +01:00
parent e391d3f63f
commit 22281e21f8
Signed by: noa
GPG key ID: 1850932741EFF672
2 changed files with 26 additions and 12 deletions

View file

@ -19,7 +19,7 @@ macro_rules! build_parser_type_enum {
#[derive(Clone)]
pub enum ParserTypes {
$(
#[cfg(feature = $feat)]
#[cfg(feature = $feat)]
$name($t),
)*
}
@ -28,18 +28,29 @@ macro_rules! build_parser_type_enum {
// add code here
fn default() -> Self {
$(
#[allow(unreachable_code)]
#[cfg(feature = $feat)]
#[allow(unreachable_code)]
return ParserTypes::$name(<$t>::default());
)*
}
}
impl ParserTypes {
pub fn announce() {
$(
#[cfg(feature = $feat)]
println!("Enabling {}", $feat);
#[cfg(not(feature = $feat))]
println!("Keeping {} disabled", $feat);
)*
}
}
macro_rules! match_parser {
($pident:ident: $parser:expr => $f:expr) => (
match &mut $parser {
$(
#[cfg(feature = $feat)]
#[cfg(feature = $feat)]
ParserTypes::$name($pident) => $f,
)*
}
@ -120,14 +131,20 @@ where
fn change_protocol(&mut self, protocol: &Protocol) {
match protocol {
#[cfg(feature="text")]
#[cfg(feature = "text")]
Protocol::Text => self.parser = ParserTypes::TextParser(TextParser::default()),
#[cfg(not(feature="text"))]
Protocol::Text => {self.writer.write(b"feature \"text\" is not enabled."); self.writer.flush();}
#[cfg(not(feature = "text"))]
Protocol::Text => {
self.writer.write(b"feature \"text\" is not enabled.");
self.writer.flush();
}
#[cfg(feature = "binary")]
Protocol::Binary => self.parser = ParserTypes::BinaryParser(BinaryParser::default()),
#[cfg(not(feature = "binary"))]
Protocol::Binary => {self.writer.write(b"feature \"binary\" is not enabled."); self.writer.flush();}
Protocol::Binary => {
self.writer.write(b"feature \"binary\" is not enabled.");
self.writer.flush();
}
}
}