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();
}
}
}

View file

@ -10,7 +10,7 @@ use std::{
use chrono::Local;
use flurry::{
config::{GRID_LENGTH, HOST, IMAGE_SAVE_INTERVAL, JPEG_UPDATE_INTERVAL},
flutclient::{FlutClient, },
flutclient::{FlutClient, ParserTypes},
grid::{self, Flut},
webapi::WebApiContext,
AsyncResult, COUNTER,
@ -102,10 +102,7 @@ async fn main() {
let grids: Arc<[Flut<u32>; GRID_LENGTH]> = [grid::Flut::init(800, 600, 0xff_00_ff_ff)].into();
tracing::trace!("created grids");
#[cfg(feature = "text")]
println!("Enabling text");
#[cfg(feature = "binary")]
println!("Enabling binary");
ParserTypes::announce();
let Ok(flut_listener) = TcpListener::bind(HOST).await else {
tracing::error!(