#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

#10 in #string-interpolation

Download history 23/week @ 2024-01-01 43/week @ 2024-01-08 53/week @ 2024-01-15 44/week @ 2024-01-22 43/week @ 2024-01-29 46/week @ 2024-02-05 58/week @ 2024-02-12 65/week @ 2024-02-19 90/week @ 2024-02-26 93/week @ 2024-03-04 78/week @ 2024-03-11 82/week @ 2024-03-18 99/week @ 2024-03-25 125/week @ 2024-04-01 71/week @ 2024-04-08 90/week @ 2024-04-15

395 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