#str #string #slice #owned #macro

str-macro

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

5 releases

✓ Uses Rust 2018 edition

0.1.4 Jan 26, 2020
0.1.3 Sep 22, 2019
0.1.2 Apr 21, 2019
0.1.1 Apr 21, 2019
0.1.0 Apr 21, 2019

#115 in Rust patterns

Download history 160/week @ 2020-02-06 196/week @ 2020-02-13 213/week @ 2020-02-20 232/week @ 2020-02-27 82/week @ 2020-03-05 107/week @ 2020-03-12 91/week @ 2020-03-19 168/week @ 2020-03-26 123/week @ 2020-04-02 91/week @ 2020-04-09 163/week @ 2020-04-16 133/week @ 2020-04-23 65/week @ 2020-04-30 150/week @ 2020-05-07 55/week @ 2020-05-14 49/week @ 2020-05-21

713 downloads per month
Used in less than 6 crates

MIT license

5KB

str-macro

Build Status

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

// Vec equivalent
let v = vec![];
assert_eq!(v.len(), 0);
  • Create an owned String from a constant str reference.
// 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;
  • 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-2020 Ammon Smith

Available under the MIT License.

No runtime deps