#str #string #slice #owned #macro

str-macro

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

6 releases (1 stable)

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

#224 in Rust patterns

Download history 1886/week @ 2022-01-29 2685/week @ 2022-02-05 2338/week @ 2022-02-12 2345/week @ 2022-02-19 2096/week @ 2022-02-26 1968/week @ 2022-03-05 1612/week @ 2022-03-12 2668/week @ 2022-03-19 2225/week @ 2022-03-26 2414/week @ 2022-04-02 2395/week @ 2022-04-09 2406/week @ 2022-04-16 1463/week @ 2022-04-23 1349/week @ 2022-04-30 1347/week @ 2022-05-07 2495/week @ 2022-05-14

6,918 downloads per month
Used in less than 9 crates

MIT license

6KB

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-2021 Ammon Smith

Available under the MIT License.

No runtime deps