rust wasm-pack build warning: private type `World` in public interface (error E0446)

60 Views Asked by At

i have this code and i dont understand why is this warrning is poping:

use wasm_bindgen::prelude::*;

#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen]
struct World {
    width: usize
}

#[wasm_bindgen]
impl World {
    pub fn new() -> World {
        World {
            width :8
        }
    }

    pub fn width(&self) -> usize {
            self.width
    }
}

Executing wasm-pack build --target web in windows

[INFO]:   Compiling to Wasm...
   Compiling snake_game v0.1.0 (C:\dev\my\rust\test\snake_game)
warning: private type `World` in public interface (error E0446)
  --> src\lib.rs:11:1
   |
11 | #[wasm_bindgen]
   | ^^^^^^^^^^^^^^^
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
   = note: `#[warn(private_in_public)]` on by default
   = note: this warning originates in the attribute macro `wasm_bindgen::prelude::__wasm_bindgen_class_marker` (in Nightly builds, run with -Z macro-backtrace for more info)

visited the link : https://github.com/rust-lang/rust/issues/34537 Didn't understand much , in simple words what is the problem ?

1

There are 1 best solutions below

0
Chayim Friedman On

Either make the functions of World private, or make World itself public. While public functions for private structs are allowed, wasm-bindgen generates some code that disallows this.