#![feature(round_char_boundary)] #![feature(exact_size_is_empty)] use std::io::Read; use std::path::Path; use organic::compare::run_anonymous_compare; use organic::compare::run_compare_on_file; #[cfg(feature = "tracing")] use crate::init_tracing::init_telemetry; #[cfg(feature = "tracing")] use crate::init_tracing::shutdown_telemetry; #[cfg(feature = "tracing")] mod init_tracing; #[cfg(not(feature = "tracing"))] fn main() -> Result<(), Box> { let rt = tokio::runtime::Runtime::new()?; let result = rt.block_on(async { let main_body_result = main_body().await; main_body_result }); result } #[cfg(feature = "tracing")] fn main() -> Result<(), Box> { let rt = tokio::runtime::Runtime::new()?; let result = rt.block_on(async { init_telemetry()?; let main_body_result = main_body().await; shutdown_telemetry()?; main_body_result }); result } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] async fn main_body() -> Result<(), Box> { let test_config = TestConfig::TestLayer(TestLayer { name: "foo", children: vec![TestConfig::SingleFile(SingleFile { file_path: Path::new("/tmp/test.org"), })], }); Ok(()) } #[derive(Debug)] enum TestConfig<'s> { TestLayer(TestLayer<'s>), SingleFile(SingleFile<'s>), } #[derive(Debug)] struct TestLayer<'s> { name: &'s str, children: Vec>, } #[derive(Debug)] struct SingleFile<'s> { file_path: &'s Path, } #[derive(Debug)] enum TestResult<'s> { ResultLayer(ResultLayer<'s>), SingleFileResult(SingleFileResult<'s>), } #[derive(Debug)] struct ResultLayer<'s> { name: &'s str, children: Vec>, } #[derive(Debug)] struct SingleFileResult<'s> { file_path: &'s Path, status: TestStatus, } #[derive(Debug)] pub(crate) enum TestStatus { Good, Bad, } impl<'s> TestConfig<'s> { async fn run_test(&self) -> TestResult<'s> { match self { TestConfig::TestLayer(test) => TestResult::ResultLayer(test.run_test().await), TestConfig::SingleFile(test) => TestResult::SingleFileResult(test.run_test().await), } } } impl<'s> SingleFile<'s> { async fn run_test(&self) -> SingleFileResult<'s> { let result = run_compare_on_file(self.file_path); SingleFileResult { file_path: self.file_path, status: if result.is_ok() { TestStatus::Good } else { TestStatus::Bad }, } } } impl<'s> TestLayer<'s> { async fn run_test(&self) -> ResultLayer<'s> { todo!() } }