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

macro join_str

Proc macro to do simple string interpolation as an array join

1 unstable release

0.1.0 May 19, 2022

#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 downloads per month
Used in 3 crates (via roead)

GPL-3.0-or-later

3KB

join_str

Simple proc macro to do simple string interpolation as an array join, since it's one of the most efficient methods.

use join_str::jstr;

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

If your interpolated code contains quotation marks, pass a raw string to the macro:

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"]}"#)
  );
}

No runtime deps