I'm working on a project which should target wasm, but some functionality will not be supported.
It looks like I can conditionally include a function in this way:
#[cfg(target_arch = "wasm32")]
fn my_func() { ... }
Or conditionally call it like so:
if cfg!(target_arch = "wasm32") {
my_func();
} else {
...
}
But how can I conditionally exclude a declaration or a block of code on wasm?
I.e. I am looking for something similar to #ifndef in c macros:
#ifndef WASM
native_only_func();
#endif
To negate condition use #[cfg(not(condition))]. You can read more about conditional compilation in this section of The Rust Reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With