https://github.com/emmiegit/str-macro
Rust str macro to bring the convenience of vec to the String type
https://github.com/emmiegit/str-macro
macros rust string
Last synced: about 1 year ago
JSON representation
Rust str macro to bring the convenience of vec to the String type
- Host: GitHub
- URL: https://github.com/emmiegit/str-macro
- Owner: emmiegit
- License: mit
- Created: 2019-04-20T21:11:46.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-07-10T22:38:22.000Z (almost 4 years ago)
- Last Synced: 2025-04-21T18:03:22.761Z (about 1 year ago)
- Topics: macros, rust, string
- Language: Rust
- Homepage:
- Size: 21.5 KB
- Stars: 13
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## str-macro
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`
```rust
// 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());
```
* Create an owned `String` from a constant str reference.
```rust
// 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;
```
* Create an owned `String` from an object which implements `ToString`.
Note that this is automatically implemented for anything that implements `Display`.
```rust
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.