#javascript #wasm-bindgen #intern #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

#26 in #intern

Download history 72/week @ 2024-08-31 28/week @ 2024-09-07 51/week @ 2024-09-14 153/week @ 2024-09-21 284/week @ 2024-09-28 268/week @ 2024-10-05 165/week @ 2024-10-12 214/week @ 2024-10-19 89/week @ 2024-10-26 41/week @ 2024-11-02 30/week @ 2024-11-09 32/week @ 2024-11-16 22/week @ 2024-11-23 33/week @ 2024-11-30 48/week @ 2024-12-07 9/week @ 2024-12-14

115 downloads per month
Used in 5 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.7–1.3MB
~27K SLoC