impl tokio's AsyncRead/Write/Seek for AFC FileDescriptor (#33)

* AsyncWrite/Read/Seek

* clean up

* use only one field to store the future

This struct should not be shared across threads because simultaneous
operations
like reading, writing, or seeking could lead to data races or
inconsistent state, because the cursor moves.

Only one operation will ever run at a time, which allows us to safely
store
different types of pending operations (read, write, or seek) in the same
field.

* consume self without mut when closing

* clippy

* Add inner_file safety tests

* more tests

---------

Co-authored-by: Jackson Coxson <jkcoxson@gmail.com>
This commit is contained in:
Abdullah Al-Banna
2025-10-28 16:57:35 +03:00
committed by GitHub
parent 105a9b2837
commit b26dd17b13
7 changed files with 827 additions and 166 deletions

View File

@@ -154,7 +154,7 @@ async fn main() {
.await
.expect("Failed to open");
let res = file.read().await.expect("Failed to read");
let res = file.read_entire().await.expect("Failed to read");
tokio::fs::write(save, res)
.await
.expect("Failed to write to file");
@@ -168,7 +168,9 @@ async fn main() {
.await
.expect("Failed to open");
file.write(&bytes).await.expect("Failed to upload bytes");
file.write_entire(&bytes)
.await
.expect("Failed to upload bytes");
} else if let Some(matches) = matches.subcommand_matches("remove") {
let path = matches.get_one::<String>("path").expect("No path passed");
afc_client.remove(path).await.expect("Failed to remove");