From 48a62fc165124d3f6a53877c7dc56697ee2e5eb2 Mon Sep 17 00:00:00 2001 From: yukirij Date: Sun, 13 Apr 2025 12:14:15 -0700 Subject: [PATCH] Add async recursion fixes. --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + src/bin/test.rs | 12 +++++++----- src/blockfile/mod.rs | 2 ++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f325849..5158c58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,17 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "async-recursion" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.4.0" @@ -291,6 +302,7 @@ dependencies = [ name = "storage" version = "0.1.0" dependencies = [ + "async-recursion", "pack", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index 92e66b6..6eb37fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,6 @@ edition = "2021" [dependencies] tokio = { version = "1.44.1", features = ["full"] } +async-recursion = "1.1.1" pack = { git = "https://git.tsukiyo.org/Utility/pack" } diff --git a/src/bin/test.rs b/src/bin/test.rs index 125d00f..5dd073f 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -6,16 +6,18 @@ async fn main() { std::fs::create_dir_all("data").ok(); - /* - if let Ok(mut bf) = BlockFile::<16>::open("data/cache_data.bin") { - if let Ok(id) = bf.insert("This is a test of the block file system.".as_bytes()) { - let data = String::from_utf8(bf.get(id).unwrap()).unwrap(); + println!("BLOCKFILE"); + + if let Ok(mut bf) = BlockFile::<16>::open("data/cache_data.bin").await { + if let Ok(id) = bf.insert("This is a test of the block file system.".as_bytes()).await { + let data = String::from_utf8(bf.get(id).await.unwrap()).unwrap(); println!("id {} = '{}'", id, data); } } else { println!("Failed to open."); } - */ + + println!("TRIEFILE"); if let Ok(mut tf) = TrieFile::<8>::open("data/cache_index.bin").await { diff --git a/src/blockfile/mod.rs b/src/blockfile/mod.rs index d2b9c76..62d691d 100644 --- a/src/blockfile/mod.rs +++ b/src/blockfile/mod.rs @@ -249,6 +249,7 @@ impl BlockFile { Ok(output) } + #[async_recursion::async_recursion] async fn allocate(&mut self, count:usize) -> Result, std::io::Error> // Mark as allocated and return the next available N blocks. // @@ -278,6 +279,7 @@ impl BlockFile { Ok(blocks) } + #[async_recursion::async_recursion] async fn allocate_traverse( &mut self, block_id:u32,