fco-dev/test-wasm-rust
1
1let wasm;2 3const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );4 5if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };6 7let cachedUint8Memory0 = null;8 9function getUint8Memory0() {10 if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {11 cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);12 }13 return cachedUint8Memory0;14}15 16function getStringFromWasm0(ptr, len) {17 ptr = ptr >>> 0;18 return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));19}20 21let cachedInt32Memory0 = null;22 23function getInt32Memory0() {24 if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {25 cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);26 }27 return cachedInt32Memory0;28}29 30function notDefined(what) { return () => { throw new Error(`${what} is not defined`); }; }31/**32*/33export const Cell = Object.freeze({ Dead:0,"0":"Dead",Alive:1,"1":"Alive", });34/**35*/36export class Universe {37 38 static __wrap(ptr) {39 ptr = ptr >>> 0;40 const obj = Object.create(Universe.prototype);41 obj.__wbg_ptr = ptr;42 43 return obj;44 }45 46 __destroy_into_raw() {47 const ptr = this.__wbg_ptr;48 this.__wbg_ptr = 0;49 50 return ptr;51 }52 53 free() {54 const ptr = this.__destroy_into_raw();55 wasm.__wbg_universe_free(ptr);56 }57 /**58 * @returns {Universe}59 */60 static new() {61 const ret = wasm.universe_new();62 return Universe.__wrap(ret);63 }64 /**65 * @returns {string}66 */67 render() {68 let deferred1_0;69 let deferred1_1;70 try {71 const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);72 wasm.universe_render(retptr, this.__wbg_ptr);73 var r0 = getInt32Memory0()[retptr / 4 + 0];74 var r1 = getInt32Memory0()[retptr / 4 + 1];75 deferred1_0 = r0;76 deferred1_1 = r1;77 return getStringFromWasm0(r0, r1);78 } finally {79 wasm.__wbindgen_add_to_stack_pointer(16);80 wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);81 }82 }83 /**84 */85 tick() {86 wasm.universe_tick(this.__wbg_ptr);87 }88 /**89 * @returns {number}90 */91 width() {92 const ret = wasm.universe_width(this.__wbg_ptr);93 return ret >>> 0;94 }95 /**96 * @returns {number}97 */98 height() {99 const ret = wasm.universe_height(this.__wbg_ptr);100 return ret >>> 0;101 }102 /**103 * @returns {number}104 */105 cells() {106 const ret = wasm.universe_cells(this.__wbg_ptr);107 return ret;108 }109 /**110 * @param {number} width111 */112 set_width(width) {113 wasm.universe_set_width(this.__wbg_ptr, width);114 }115 /**116 * @param {number} height117 */118 set_height(height) {119 wasm.universe_set_height(this.__wbg_ptr, height);120 }121 /**122 * @param {number} row123 * @param {number} col124 */125 toggle_cell(row, col) {126 wasm.universe_toggle_cell(this.__wbg_ptr, row, col);127 }128}129 130async function __wbg_load(module, imports) {131 if (typeof Response === 'function' && module instanceof Response) {132 if (typeof WebAssembly.instantiateStreaming === 'function') {133 try {134 return await WebAssembly.instantiateStreaming(module, imports);135 136 } catch (e) {137 if (module.headers.get('Content-Type') != 'application/wasm') {138 console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);139 140 } else {141 throw e;142 }143 }144 }145 146 const bytes = await module.arrayBuffer();147 return await WebAssembly.instantiate(bytes, imports);148 149 } else {150 const instance = await WebAssembly.instantiate(module, imports);151 152 if (instance instanceof WebAssembly.Instance) {153 return { instance, module };154 155 } else {156 return instance;157 }158 }159}160 161function __wbg_get_imports() {162 const imports = {};163 imports.wbg = {};164 imports.wbg.__wbg_random_5f61cd0d6777a993 = typeof Math.random == 'function' ? Math.random : notDefined('Math.random');165 imports.wbg.__wbindgen_throw = function(arg0, arg1) {166 throw new Error(getStringFromWasm0(arg0, arg1));167 };168 169 return imports;170}171 172function __wbg_init_memory(imports, maybe_memory) {173 174}175 176function __wbg_finalize_init(instance, module) {177 wasm = instance.exports;178 __wbg_init.__wbindgen_wasm_module = module;179 cachedInt32Memory0 = null;180 cachedUint8Memory0 = null;181 182 183 return wasm;184}185 186function initSync(module) {187 if (wasm !== undefined) return wasm;188 189 const imports = __wbg_get_imports();190 191 __wbg_init_memory(imports);192 193 if (!(module instanceof WebAssembly.Module)) {194 module = new WebAssembly.Module(module);195 }196 197 const instance = new WebAssembly.Instance(module, imports);198 199 return __wbg_finalize_init(instance, module);200}201 202async function __wbg_init(input) {203 if (wasm !== undefined) return wasm;204 205 if (typeof input === 'undefined') {206 input = new URL('rust_webpack_template_bg.wasm', import.meta.url);207 }208 const imports = __wbg_get_imports();209 210 if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {211 input = fetch(input);212 }213 214 __wbg_init_memory(imports);215 216 const { instance, module } = await __wbg_load(await input, imports);217 218 return __wbg_finalize_init(instance, module);219}220 221export { initSync }222export default __wbg_init;223 