alef 0.110.4

Opinionated polyglot binding generator for Rust libraries
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{#-
  The parameter is a borrow on purpose: wasm-bindgen lowers a by-value exported-struct argument
  through `__destroy_into_raw()`, which kills the handle the caller assigned (alef#470, #473). Do
  not "fix" the `get x(): T | undefined` / `set x(value: T)` asymmetry this produces for an
  optional field by reverting to by-value -- the asymmetry is inherent to borrowing on set
  (`Option<&T>` has no `OptionFromWasmAbi` impl) and TypeScript accepts it from 5.1 on. Clearing
  an optional field is restored by the companion `clear{Field}()` in gen_class_field_clear.jinja.

  `setter_ident` is carried separately from `field_ident` because the tagged-data-enum payload
  path mints a method name the struct field name does not predict (`_0` becomes `field_0`). ~keep
-#}
#[wasm_bindgen(setter{{ js_name_attr }})]
pub fn {{ setter_ident }}(&mut self, value: &{{ class_type }}) {
    self.{{ field_ident }} = {% if optional %}Some(value.clone()){% else %}value.clone(){% endif %};
}