Macro boa_engine::js_string
source · macro_rules! js_string { () => { ... }; ($s:literal) => { ... }; ($s:expr) => { ... }; ( $x:expr, $y:expr ) => { ... }; ( $( $s:expr ),+ ) => { ... }; }
Expand description
Utility macro to create a JsString.
§Examples
You can call the macro without arguments to create an empty JsString:
use boa_engine::js_string;
use boa_engine::string::utf16;
let empty_str = js_string!();
assert!(empty_str.is_empty());You can create a JsString from a string literal, which completely skips the runtime
conversion from &str to &[u16]:
let hw = js_string!("Hello, world!");
assert_eq!(&hw, utf16!("Hello, world!"));Any &[u16] slice is a valid JsString, including unpaired surrogates:
let array = js_string!(&[0xD8AFu16, 0x00A0, 0xD8FF, 0x00F0]);You can also pass it any number of &[u16] as arguments to create a new JsString with
the concatenation of every slice:
const NAME: &[u16] = utf16!("human! ");
let greeting = js_string!("Hello, ");
let msg = js_string!(&greeting, &NAME, utf16!("Nice to meet you!"));
assert_eq!(&msg, utf16!("Hello, human! Nice to meet you!"));