#string #macro #slice #owned

str-macro

The str!() macro, similar to vec![] but for strings

7 releases (2 stable)

1.0.1 Oct 16, 2025
1.0.0 Feb 13, 2021
0.1.4 Jan 26, 2020
0.1.3 Sep 22, 2019
0.1.2 Apr 21, 2019

#540 in Rust patterns

Download history 2121/week @ 2026-01-23 1825/week @ 2026-01-30 1841/week @ 2026-02-06 2788/week @ 2026-02-13 2331/week @ 2026-02-20 2649/week @ 2026-02-27 3555/week @ 2026-03-06 4085/week @ 2026-03-13 2936/week @ 2026-03-20 7719/week @ 2026-03-27 4362/week @ 2026-04-03 7911/week @ 2026-04-10 6364/week @ 2026-04-17 4134/week @ 2026-04-24 7568/week @ 2026-05-01 12327/week @ 2026-05-08

34,500 downloads per month
Used in 11 crates

MIT license

7KB

str-macro

Rust CI badge

Rust crate for the str!() macro, which makes the conveniences available from vec![] available for String as well.

Has no dependencies, and should work on any Rust release channel.

  • Create an empty String
// Vec equivalent
let v = vec![];
assert_eq!(v, Vec::new());
assert!(v.is_empty());

// String
let s = str!();
assert_eq!(s, String::new());
assert!(s.is_empty());
  • Create an owned String from a constant str reference.
// Vec equivalent
let v = vec!["alpha", "beta", "gamma"];
assert_eq!(&v, &["alpha", "beta", "gamma"];
assert_eq!(v.len(), 3);

// String
let s = str!("alpha beta gamma");
assert_eq!(&s, "alpha beta gamma");
let _: String = s;
  • Create an owned String from an object which implements ToString.

Note that this is automatically implemented for anything that implements Display.

let s = str!(2194);
assert_eq!(&s, "2194");

let s = str!(Ipv4Addr::new(127, 0, 0, 1));
assert_eq!(&s, "127.0.0.1");

Copyright (C) 2019-2025 Emmie Maeda

Available under the MIT License.

No runtime deps