Crates.io | str-macro |
lib.rs | str-macro |
version | 1.0.0 |
source | src |
created_at | 2019-04-21 00:25:57.435106 |
updated_at | 2021-02-13 02:45:18.40642 |
description | The str!() macro, similar to vec![] but for strings |
homepage | |
repository | https://github.com/ammongit/str-macro |
max_upload_size | |
id | 129164 |
size | 8,689 |
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.
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());
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;
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.