[−][src]Crate str_macro
Creates a String
with the given contents.
str!
allows you to conveniently create owned String
s,
similar to the vec!
macro found in the Rust stdlib.
- Create an empty
String
// String let s = str!(); assert_eq!(s, String::new()); // Vec equivalent let v = vec![]; assert_eq!(v.len(), 0);
// Vec equivalent let v = vec!["alpha", "beta", "gamma"]; assert_eq!(v.len(), 3); // String let s = str!("alpha beta gamma"); assert_eq!(&s, "alpha beta gamma"); let _: String = s;
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");
Macros
str | Create an owned |