#string-interpolation #join #array #proc-macro #jstr

join_str

过程宏,用于将简单的字符串插值作为数组连接

1 个不稳定版本

0.1.0 2022年5月19日

#11 in #string-interpolation

Download history 82/week @ 2024-03-13 81/week @ 2024-03-20 112/week @ 2024-03-27 104/week @ 2024-04-03 76/week @ 2024-04-10 94/week @ 2024-04-17 97/week @ 2024-04-24 98/week @ 2024-05-01 78/week @ 2024-05-08 85/week @ 2024-05-15 87/week @ 2024-05-22 93/week @ 2024-05-29 91/week @ 2024-06-05 89/week @ 2024-06-12 107/week @ 2024-06-19 84/week @ 2024-06-26

379 每月下载量
3 个crate中使用 (通过 roead)

GPL-3.0-or-later

3KB

join_str

一个简单的过程宏,用于将简单的字符串插值作为数组连接,因为它是最有效的方法之一。

use join_str::jstr;

fn main () {
  let actor_name = "GameROMPlayer";
  assert_eq!(
    String::from("Actor/ActorLink/GameROMPlayer.bxml"),
    jstr!("Actor/ActorLink/{actor_name}.bxml")
  );
}

如果您的插值代码包含引号,请向宏传递原始字符串

use join_str::jstr;
use std::collections::HashMap;

fn main () {
  let mut actors: HashMap<String, String> = HashMap::new();
  actors.insert(String::from("GameROMPlayer"), String::from("Link"));
  assert_eq!(
    String::from("The GameROMPlayer actor is Link"),
    jstr!(r#"The GameROMPlayer actor is {actors["GameROMPlayer"]}"#)
  );
}

无运行时依赖