File: final.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,245,420 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (40 lines) | stat: -rw-r--r-- 938 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;

#[wasm_bindgen]
extern "C" {
    type Math;
    #[wasm_bindgen(static_method_of = Math, final)]
    fn log(f: f32) -> f32;
}

#[wasm_bindgen(module = "tests/wasm/final.js")]
extern "C" {
    type MyType;
    #[wasm_bindgen(constructor, final)]
    fn new(x: u32) -> MyType;
    #[wasm_bindgen(static_method_of = MyType, final)]
    fn foo(a: &str) -> String;
    #[wasm_bindgen(method, final)]
    fn bar(this: &MyType, arg: bool) -> f32;

    #[wasm_bindgen(method, getter, final)]
    fn a(this: &MyType) -> u32;
    #[wasm_bindgen(method, setter, final)]
    fn set_a(this: &MyType, a: u32);
}

#[wasm_bindgen_test]
fn simple() {
    assert_eq!(Math::log(1.0), 0.0);
}

#[wasm_bindgen_test]
fn classes() {
    assert_eq!(MyType::foo("x"), "xy");
    let x = MyType::new(2);
    assert_eq!(x.bar(true), 3.2);
    assert_eq!(x.a(), 1);
    x.set_a(3);
    assert_eq!(x.a(), 3);
}