T parameter | &T parameter | &mut T parameter | T return value | Option<T> parameter | Option<T> return value | JavaScript representation |
Yes | No | No | Yes | Yes | Yes | A JavaScript number value |
# #![allow(unused_variables)]
#fn main() {
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn take_number_by_value(x: u32) {}
#[wasm_bindgen]
pub fn return_number() -> f64 {
42.0
}
#[wasm_bindgen]
pub fn take_option_number(x: Option<u8>) {}
#[wasm_bindgen]
pub fn return_option_number() -> Option<i16> {
Some(-300)
}
#}
import {
take_number_by_value,
return_number,
take_option_number,
return_option_number,
} from './guide_supported_types_examples';
take_number_by_value(42);
let x = return_number();
console.log(typeof x); // "number"
take_option_number(null);
take_option_number(undefined);
take_option_number(13);
let y = return_option_number();
if (y == null) {
// ...
} else {
console.log(typeof y); // "number"
}