alef 0.101.0

Opinionated polyglot binding generator for Rust libraries
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
{#-
  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). 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. ~keep
-#}
#[wasm_bindgen(setter{{ js_name_attr }})]
pub fn set_{{ field_name }}(&mut self, value: &{{ class_type }}) {
    self.{{ field_name }} = {% if optional %}Some(value.clone()){% else %}value.clone(){% endif %};
}