rustwasm-bindgenrust-wasm

usize - alias for max unsigned integer type, in wit


How to define usize type in a .wit file. If instead of usize, I type in u64 it works. But want to know if there is a type of max unsigned integer that matches with usize.

get-size: func() -> result<usize, type-error>;

Error

0: failed to resolve directory while parsing WIT for path [./wit]
1: failed to parse package: ./wit
2: name `usize` is not defined
        --> ./wit/a.wit:52:42
         |
     52  |         get-size: func() -> result<usize, type-error>;
         |        

Solution

  • From the wasm-bindgen docs:

    Note: Wasm is currently a 32-bit architecture, so isize and usize are 32-bit integers and "fit" into a JavaScript Number.

    So you can use a u32 in place of usize.