#javascript #intern #wasm-bindgen #interning

js-intern-core

Internal implementation details for the js-intern crate

2 releases

0.3.1 Jul 5, 2019
0.3.0 Jul 5, 2019

#27 in #intern

Download history 38/week @ 2024-01-08 26/week @ 2024-01-15 48/week @ 2024-01-22 31/week @ 2024-01-29 35/week @ 2024-02-05 45/week @ 2024-02-12 31/week @ 2024-02-19 93/week @ 2024-02-26 12/week @ 2024-03-04 90/week @ 2024-03-11 44/week @ 2024-03-18 84/week @ 2024-03-25 80/week @ 2024-04-01 34/week @ 2024-04-08 25/week @ 2024-04-15 56/week @ 2024-04-22

202 downloads per month
Used in 4 crates (2 directly)

MIT license

7KB
108 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

~0.8–1.4MB
~29K SLoC