Simplicio
Get rid of the annoying boilerplate in Rust and simplify creation of Strings and HashMaps.
Features
s!() can be used to:
- create a new
String
- convert any value that implements the
Display trait into a string
- concatinate values together that implement the
Display trait
- concatinate while inserting a space between each value with the
. prefix (e.g. s!(.a, b, c))
cnct!() is a wrapper around s!() for preferential purposes
map() creates a HashMap with initial values or from a Vec/array of tuple pairs
map!(k1 v1, k1 v2) | map!(k1: v1, k2:v2) | map!(k1 => v1, k2 => v2) | map!(k1 -> v1, k2 -> v2)
Getting Started
To start using Simplicio, add the following to your Cargo.toml:
[dependencies]
simplicio = "0.1.2"
- Minimum supported Rust version:
1.56.1
Usage
String creation and concatination
use simplicio::{s, cnct};
enum Enum { Value } impl std::fmt::Display for Enum { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self { Enum::Value => write!(f, "value"), }
}
}
fn main() {
assert_eq!(String::new(), s!()); assert_eq!(String::from("This is a String"), s!("This is a String"));
assert_eq!(true.to_string(), s!(true)); assert_eq!(123840.to_string(), s!(123840)); assert_eq!(Enum::Value.to_string(), s!(Enum::Value));
let (a, b, c, d) = ("This", "is", "a", "String");
assert_eq!(String::from("This is a String"), cnct!(.a, b, c, d)); assert_eq!(s!(a, b, c, d), cnct!(a, b, c ,d)); }
Creating HashMaps
use simplicio::*;
fn main() {
let mut tester = std::collections::HashMap::new();
tester.insert("k1", "v1");
tester.insert("k2", "v2");
assert_eq!(map!("k1""v1", "k2" "v2"), tester); assert_eq!(map!("k1":"v1", "k2" : "v2"), tester); assert_eq!(map!("k1"=>"v1", "k2" => "v2"), tester); assert_eq!(map!("k1"->"v1", "k2" -> "v2"), tester); assert_eq!(map!("k1"["v1"], "k2" ["v2"]), tester); assert_eq!(map!([("k1", "v1"), ("k2", "v2")]), tester);
let vecmap = Vec::from([("k1", "v1"), ("k2", "v2")]);
assert_eq!(map!(vecmap), tester);
let arrmap = [("k1", "v1"), ("k2", "v2")];
assert_eq!(map!(arrmap), tester); }
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
._. why would you do this?