1

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
markalex
  • 8,623
  • 2
  • 7
  • 32
sak
  • 2,612
  • 24
  • 55

1 Answers1

3

To negate condition use #[cfg(not(condition))]. You can read more about conditional compilation in this section of The Rust Reference.

Aleksander Krauze
  • 3,115
  • 7
  • 18