#string #slice #macro #str #owned

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

#623 in Rust patterns

Download history 5174/week @ 2024-03-14 7871/week @ 2024-03-21 4738/week @ 2024-03-28 7850/week @ 2024-04-04 5867/week @ 2024-04-11 9292/week @ 2024-04-18 5610/week @ 2024-04-25 6166/week @ 2024-05-02 9008/week @ 2024-05-09 16785/week @ 2024-05-16 8740/week @ 2024-05-23 7727/week @ 2024-05-30 9705/week @ 2024-06-06 9669/week @ 2024-06-13 8574/week @ 2024-06-20 3685/week @ 2024-06-27

33,645 downloads per month
Used in 11 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