Expand description
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, strings 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 strEg:js_intern!("str")f64,f32,u8,u16,u32,i8,i16,i32Eg:js_intern(1.0)boolEg: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 memory allocator for large slices that don’t escape the stack.
Macros§
- js_
intern - Stores one copy of each distinct JavaScript primitive.
For example,
js_intern!("string")evaluates to a&JsValuebut only does the translation from the utf-8 Rust string to the utf-16 JavaScript string the first time the expression is evaluated. Furthermore, strings are de-duplicated across the program. So, any timejs_intern!("string")is used in the program, the same instance of the JavaScript string is used. - try_
js_ intern - Does a very conservative check to see if an expression is a candidate for interning.
If the expression is a candidate to be interned this will return
js_intern!(...)Otherwise, the original expression is returned.