docs: Clarify the rationale for split trait implementations for native and WASM targets
This commit is contained in:
parent
03533f9216
commit
017fc897f4
@ -3,6 +3,11 @@ use evm_client::{EvmClient, EvmProvider, Signer};
|
||||
// Dummy signer that returns a known Ethereum address (Vitalik's address)
|
||||
struct DummySigner;
|
||||
|
||||
// --- IMPORTANT ---
|
||||
// The Signer trait's async methods require different trait bounds on native vs WASM:
|
||||
// - Native Rust: futures must be Send, so use #[async_trait::async_trait]
|
||||
// - WASM (wasm32): futures do NOT require Send, so use #[async_trait::async_trait(?Send)]
|
||||
// This split is required for cross-platform test compatibility. DO NOT merge these impls!
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[async_trait::async_trait]
|
||||
impl Signer for DummySigner {
|
||||
@ -35,6 +40,7 @@ async fn test_get_balance_vitalik() {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
// See explanation above for why this impl uses ?Send
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Signer for DummySigner {
|
||||
|
@ -4,6 +4,11 @@ use evm_client::{EvmClient, EvmProvider, Signer, EvmError};
|
||||
|
||||
struct DummySigner;
|
||||
|
||||
// --- IMPORTANT ---
|
||||
// The Signer trait's async methods require different trait bounds on native vs WASM:
|
||||
// - Native Rust: futures must be Send, so use #[async_trait::async_trait]
|
||||
// - WASM (wasm32): futures do NOT require Send, so use #[async_trait::async_trait(?Send)]
|
||||
// This split is required for cross-platform test compatibility. DO NOT merge these impls!
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl Signer for DummySigner {
|
||||
@ -15,6 +20,7 @@ impl Signer for DummySigner {
|
||||
}
|
||||
}
|
||||
|
||||
// See explanation above for why this impl uses #[async_trait::async_trait]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[async_trait::async_trait]
|
||||
impl Signer for DummySigner {
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This test file is only compiled for wasm32. The DummySigner uses #[async_trait::async_trait(?Send)]
|
||||
// because WASM async traits do not require Send. See balance.rs or evm_client.rs for the trait bound split rationale.
|
||||
#![cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::*;
|
||||
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
|
||||
|
Loading…
Reference in New Issue
Block a user