#javascript #intern #wasm-bindgen #interning

macro js-intern-proc-macro

Internal implementation details for the js-intern crate

2 releases

0.3.1 Jul 5, 2019
0.3.0 Jul 5, 2019

#29 in #intern

Download history 90/week @ 2024-03-12 47/week @ 2024-03-19 72/week @ 2024-03-26 74/week @ 2024-04-02 25/week @ 2024-04-09 24/week @ 2024-04-16 64/week @ 2024-04-23 48/week @ 2024-04-30 35/week @ 2024-05-07 45/week @ 2024-05-14 58/week @ 2024-05-21 28/week @ 2024-05-28 30/week @ 2024-06-04 16/week @ 2024-06-11 25/week @ 2024-06-18 17/week @ 2024-06-25

94 downloads per month
Used in 5 crates (via js-intern)

MIT license

10KB
135 lines

A macro for interning JavaScript primitives.

Stores one copy of each distinct JavaScript primitive. For example, js_intern!("string") evaluates to a &JsValue but uses only one heap allocation and a one-time translation from the utf-8 Rust string to the utf-16 JavaScript string the first time the expression is evaluated. Furthermore, values are de-duplicated across the program. So, any time js_intern!(1.0) is used in the program, the same instance of the JavaScript number is used.

Supported types

  • &'static str Eg: js_intern!("str")
  • f64, f32 u8, u16, u32, i8, i16, i32 Eg: js_intern(1.0)
  • bool Eg: js_intern(true)

Related

If you like this, you may like these other crates by Zac Burns (That3Percent)

  • js-object A macro for creating JavaScript objects
  • soa-vec A struct of arrays layout with a Vec of tuple API
  • second-stack A Rust memory allocator for large slices that don't escape the stack.

Dependencies

~2.5MB
~57K SLoC