Cfg wasm32 // conditional compilation

  1. I am a bit confused by

  2. What is the "correct" way to have a piece of code that compiles only under the wasm32 target?

#[cfg(target_arch = "wasm32")]
fn hello() {
    println!("with wasm")!

#[cfg(not(target_arch = "wasm32"))]
fn hello() {
    println!("not wasm")!

BTW. I can't find where this feature is documented in the second edition of the book.

1 Like

Thanks or the sample code!