Expand description
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
// 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());
// 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;
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
String
.