Movatterモバイル変換


[0]ホーム

URL:


Docs.rs

js_string

Macrojs_string 

Source
macro_rules! js_string {    () => { ... };    ($s:literal) => { ... };    ($s:expr) => { ... };    ( $x:expr, $y:expr ) => { ... };    ( $( $s:expr ),+ ) => { ... };}
Expand description

Utility macro to create aJsString.

§Examples

You can call the macro without arguments to create an emptyJsString:

useboa_engine::js_string;letempty_str =js_string!();assert!(empty_str.is_empty());

You can create aJsString from a string literal, which completely skips the runtimeconversion from&str to&[u16]:

lethw =js_string!("Hello, world!");assert_eq!(&hw,"Hello, world!");

Any&[u16] slice is a validJsString, including unpaired surrogates:

letarray =js_string!(&[0xD8AFu16,0x00A0,0xD8FF,0x00F0]);

You can also pass it any number of&[u16] as arguments to create a newJsString withthe concatenation of every slice:

constNAME: JsStr<'_> =js_str!("human! ");letgreeting =js_string!("Hello, ");letmsg =js_string!(&greeting, NAME,js_str!("Nice to meet you!"));assert_eq!(&msg,"Hello, human! Nice to meet you!");

[8]ページ先頭

©2009-2025 Movatter.jp