string-literals
A very tiny crate with Rust macros to more easily create String types.
When creating string literals in Rust, the given type is &str
. To create an owned String
type,
you either need to:
- pass in the literal to
String::from()
, - call
.to_owned()
, or.to_string()
on the&str
literal
This crate aims to make this slightly more ergonomic; see examples below in the Usage section.
Install
cargo add string-literals
Usage
Strings
use s;
let old = "Hello, world!".to_owned;
let new = s!;
Arrays, vectors
use ;
let old_arr: = ;
let new_arr: = string_arr!;
let old_vec = vec!;
let new_vec = string_vec!;
Hash maps
use HashMap;
use string_hashmap;
let mut old1: = new;
old1.insert;
old1.insert;
let old2: = from;
let new: = string_hashmap! ;
License
Licensed under either of
- Apache License, Version 2.0 (
LICENSE-APACHE
or http://www.apache.org/licenses/LICENSE-2.0) - MIT license (
LICENSE-MIT
or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.