This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal-reqsign.git
The following commit(s) were added to refs/heads/main by this push:
new c7953e5 feat(context-file-read-tokio): Allow file read tokio been
built on wasm (#654)
c7953e5 is described below
commit c7953e52e3daf8ed328dec2d34b5f89df9b6643a
Author: Xuanwo <[email protected]>
AuthorDate: Mon Oct 13 17:12:26 2025 +0900
feat(context-file-read-tokio): Allow file read tokio been built on wasm
(#654)
Technically, file-read-tokio doesn't support WASM at all. But it's still
useful to make this crate available on WASM so users don't have to
juggle features and target configurations.
Signed-off-by: Xuanwo <[email protected]>
---
context/file-read-tokio/Cargo.toml | 2 ++
context/file-read-tokio/src/lib.rs | 11 +++++++++++
2 files changed, 13 insertions(+)
diff --git a/context/file-read-tokio/Cargo.toml
b/context/file-read-tokio/Cargo.toml
index b8599c4..8248096 100644
--- a/context/file-read-tokio/Cargo.toml
+++ b/context/file-read-tokio/Cargo.toml
@@ -32,6 +32,8 @@ rust-version.workspace = true
anyhow = { workspace = true }
async-trait = { workspace = true }
reqsign-core = { workspace = true }
+
+[target.'cfg(not(target_family = "wasm"))'.dependencies]
tokio = { version = "1", features = ["fs"] }
[dev-dependencies]
diff --git a/context/file-read-tokio/src/lib.rs
b/context/file-read-tokio/src/lib.rs
index 05a155d..565c1c1 100644
--- a/context/file-read-tokio/src/lib.rs
+++ b/context/file-read-tokio/src/lib.rs
@@ -74,6 +74,7 @@ use reqsign_core::{Error, FileRead, Result};
#[derive(Debug, Clone, Copy, Default)]
pub struct TokioFileRead;
+#[cfg(not(target_family = "wasm"))]
#[async_trait]
impl FileRead for TokioFileRead {
async fn file_read(&self, path: &str) -> Result<Vec<u8>> {
@@ -82,3 +83,13 @@ impl FileRead for TokioFileRead {
.map_err(|e| Error::unexpected("failed to read
file").with_source(e))
}
}
+
+#[cfg(target_family = "wasm")]
+#[async_trait]
+impl FileRead for TokioFileRead {
+ async fn file_read(&self, _path: &str) -> Result<Vec<u8>> {
+ Err(Error::unexpected(
+ "TokioFileRead is unsupported on wasm targets",
+ ))
+ }
+}