Debian Codegraph @

.cargo/vendor/wasm-bindgen/guide/src/reference/attributes/on-js-imports/js_class.md

raw
1 # `js_class = "Blah"`
2
3 The `js_class` attribute can be used in conjunction with the `method` attribute
4 to bind methods of imported JavaScript classes that have been renamed on the
5 Rust side.
6
7 ```rust
8 #[wasm_bindgen]
9 extern "C" {
10 // We don't want to import JS strings as `String`, since Rust already has a
11 // `String` type in its prelude, so rename it as `JsString`.
12 #[wasm_bindgen(js_name = String)]
13 type JsString;
14
15 // This is a method on the JavaScript "String" class, so specify that with
16 // the `js_class` attribute.
17 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
18 fn char_at(this: &JsString, index: u32) -> JsString;
19 }
20 ```