Crate str_macro[][src]

Creates a String with the given contents.

str! allows you to conveniently create owned Strings, similar to the vec! macro found in the Rust stdlib.

// Vec equivalent
let v = vec![];
assert_eq!(v, Vec::new());

// String
let s = str!();
assert_eq!(s, String::new());
  • 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;

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, "");



Create an owned String.