Hit recursive async.

This commit is contained in:
Tom Alexander 2023-10-11 19:41:32 -04:00
parent a1f8cbe079
commit 5f93cabff5
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 44 additions and 29 deletions

View File

@ -2,6 +2,7 @@
#![feature(exact_size_is_empty)]
use std::io::Read;
use std::path::Path;
use std::path::PathBuf;
use organic::compare::run_anonymous_compare;
use organic::compare::run_compare_on_file;
@ -37,47 +38,53 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
let test_config = TestConfig::TestLayer(TestLayer {
name: "foo",
children: vec![TestConfig::SingleFile(SingleFile {
file_path: Path::new("/tmp/test.org"),
})],
let single_file = TestConfig::SingleFile(SingleFile {
file_path: PathBuf::from("/tmp/test.org"),
});
// let result = single_file.run_test().await;
let result = tokio::spawn(single_file.run_test());
println!("{:?}", result);
// 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>),
enum TestConfig {
TestLayer(TestLayer),
SingleFile(SingleFile),
}
#[derive(Debug)]
struct TestLayer<'s> {
name: &'s str,
children: Vec<TestConfig<'s>>,
struct TestLayer {
name: String,
children: Vec<TestConfig>,
}
#[derive(Debug)]
struct SingleFile<'s> {
file_path: &'s Path,
struct SingleFile {
file_path: PathBuf,
}
#[derive(Debug)]
enum TestResult<'s> {
ResultLayer(ResultLayer<'s>),
SingleFileResult(SingleFileResult<'s>),
enum TestResult {
ResultLayer(ResultLayer),
SingleFileResult(SingleFileResult),
}
#[derive(Debug)]
struct ResultLayer<'s> {
name: &'s str,
children: Vec<TestResult<'s>>,
struct ResultLayer {
name: String,
children: Vec<TestResult>,
}
#[derive(Debug)]
struct SingleFileResult<'s> {
file_path: &'s Path,
struct SingleFileResult {
file_path: PathBuf,
status: TestStatus,
}
@ -87,8 +94,8 @@ pub(crate) enum TestStatus {
Bad,
}
impl<'s> TestConfig<'s> {
async fn run_test(&self) -> TestResult<'s> {
impl TestConfig {
async fn run_test(self) -> TestResult {
match self {
TestConfig::TestLayer(test) => TestResult::ResultLayer(test.run_test().await),
TestConfig::SingleFile(test) => TestResult::SingleFileResult(test.run_test().await),
@ -96,9 +103,9 @@ impl<'s> TestConfig<'s> {
}
}
impl<'s> SingleFile<'s> {
async fn run_test(&self) -> SingleFileResult<'s> {
let result = run_compare_on_file(self.file_path);
impl SingleFile {
async fn run_test(self) -> SingleFileResult {
let result = run_compare_on_file(&self.file_path);
SingleFileResult {
file_path: self.file_path,
status: if result.is_ok() {
@ -110,8 +117,16 @@ impl<'s> SingleFile<'s> {
}
}
impl<'s> TestLayer<'s> {
async fn run_test(&self) -> ResultLayer<'s> {
todo!()
impl TestLayer {
async fn run_test(self) -> ResultLayer {
let mut children = Vec::with_capacity(self.children.len());
for config in self.children {
let result = config.run_test().await;
children.push(result);
}
ResultLayer {
name: self.name,
children,
}
}
}