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

@ -28,13 +28,24 @@ macro_rules! build_parser_type_enum {
// add code here // add code here
fn default() -> Self { fn default() -> Self {
$( $(
#[allow(unreachable_code)]
#[cfg(feature = $feat)] #[cfg(feature = $feat)]
#[allow(unreachable_code)]
return ParserTypes::$name(<$t>::default()); 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 { macro_rules! match_parser {
($pident:ident: $parser:expr => $f:expr) => ( ($pident:ident: $parser:expr => $f:expr) => (
match &mut $parser { match &mut $parser {
@ -123,11 +134,17 @@ where
#[cfg(feature = "text")] #[cfg(feature = "text")]
Protocol::Text => self.parser = ParserTypes::TextParser(TextParser::default()), Protocol::Text => self.parser = ParserTypes::TextParser(TextParser::default()),
#[cfg(not(feature = "text"))] #[cfg(not(feature = "text"))]
Protocol::Text => {self.writer.write(b"feature \"text\" is not enabled."); self.writer.flush();} Protocol::Text => {
self.writer.write(b"feature \"text\" is not enabled.");
self.writer.flush();
}
#[cfg(feature = "binary")] #[cfg(feature = "binary")]
Protocol::Binary => self.parser = ParserTypes::BinaryParser(BinaryParser::default()), Protocol::Binary => self.parser = ParserTypes::BinaryParser(BinaryParser::default()),
#[cfg(not(feature = "binary"))] #[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 chrono::Local;
use flurry::{ use flurry::{
config::{GRID_LENGTH, HOST, IMAGE_SAVE_INTERVAL, JPEG_UPDATE_INTERVAL}, config::{GRID_LENGTH, HOST, IMAGE_SAVE_INTERVAL, JPEG_UPDATE_INTERVAL},
flutclient::{FlutClient, }, flutclient::{FlutClient, ParserTypes},
grid::{self, Flut}, grid::{self, Flut},
webapi::WebApiContext, webapi::WebApiContext,
AsyncResult, COUNTER, 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(); let grids: Arc<[Flut<u32>; GRID_LENGTH]> = [grid::Flut::init(800, 600, 0xff_00_ff_ff)].into();
tracing::trace!("created grids"); tracing::trace!("created grids");
#[cfg(feature = "text")] ParserTypes::announce();
println!("Enabling text");
#[cfg(feature = "binary")]
println!("Enabling binary");
let Ok(flut_listener) = TcpListener::bind(HOST).await else { let Ok(flut_listener) = TcpListener::bind(HOST).await else {
tracing::error!( tracing::error!(