feature protocols (#55)
Feature flags are dumb so I can't make everything in seperate crates. but now you can select them with `--features`
This commit is contained in:
commit
340abecce8
3 changed files with 52 additions and 7 deletions
|
|
@ -25,6 +25,11 @@ tower-http = { version = "0.6.1", features = ["fs", "trace"] }
|
|||
tracing = "0.1.40"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||
|
||||
[features]
|
||||
default = ["text", "binary"]
|
||||
text = []
|
||||
binary = []
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "*"
|
||||
test-case = "*"
|
||||
|
|
|
|||
|
|
@ -14,17 +14,43 @@ use crate::{
|
|||
};
|
||||
|
||||
macro_rules! build_parser_type_enum {
|
||||
($($name:ident: $t:ty,)*) => {
|
||||
($($name:ident: $t:ty: $feat:expr,)*) => {
|
||||
|
||||
#[derive(Clone)]
|
||||
enum ParserTypes {
|
||||
$($name($t),)*
|
||||
pub enum ParserTypes {
|
||||
$(
|
||||
#[cfg(feature = $feat)]
|
||||
$name($t),
|
||||
)*
|
||||
}
|
||||
|
||||
impl std::default::Default for ParserTypes {
|
||||
// add code here
|
||||
fn default() -> Self {
|
||||
$(
|
||||
#[cfg(feature = $feat)]
|
||||
#[allow(unreachable_code)]
|
||||
return ParserTypes::$name(<$t>::default());
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
impl ParserTypes {
|
||||
pub fn announce() {
|
||||
$(
|
||||
#[cfg(feature = $feat)]
|
||||
tracing::info!("Enabled {}", $feat);
|
||||
#[cfg(not(feature = $feat))]
|
||||
tracing::info!("Disabled {}", $feat);
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! match_parser {
|
||||
($pident:ident: $parser:expr => $f:expr) => (
|
||||
match &mut $parser {
|
||||
$(
|
||||
#[cfg(feature = $feat)]
|
||||
ParserTypes::$name($pident) => $f,
|
||||
)*
|
||||
}
|
||||
|
|
@ -34,8 +60,8 @@ macro_rules! build_parser_type_enum {
|
|||
}
|
||||
|
||||
build_parser_type_enum! {
|
||||
TextParser: TextParser,
|
||||
BinaryParser: BinaryParser,
|
||||
TextParser: TextParser: "text",
|
||||
BinaryParser: BinaryParser: "binary",
|
||||
}
|
||||
|
||||
pub struct FlutClient<R, W>
|
||||
|
|
@ -105,8 +131,20 @@ where
|
|||
|
||||
fn change_protocol(&mut self, protocol: &Protocol) {
|
||||
match protocol {
|
||||
#[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(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +153,7 @@ where
|
|||
reader: BufReader::new(reader),
|
||||
writer: BufWriter::new(writer),
|
||||
grids,
|
||||
parser: ParserTypes::TextParser(TextParser::default()),
|
||||
parser: ParserTypes::default(),
|
||||
counter: 0,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,6 +102,8 @@ async fn main() {
|
|||
let grids: Arc<[Flut<u32>; GRID_LENGTH]> = [grid::Flut::init(800, 600, 0xff_00_ff_ff)].into();
|
||||
tracing::trace!("created grids");
|
||||
|
||||
ParserTypes::announce();
|
||||
|
||||
let Ok(flut_listener) = TcpListener::bind(HOST).await else {
|
||||
tracing::error!(
|
||||
"Was unable to bind to {HOST}, please check if a different process is bound"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue