5 个版本
0.1.5 | 2023 年 7 月 16 日 |
---|---|
0.1.4 | 2023 年 7 月 15 日 |
0.1.3 | 2023 年 6 月 20 日 |
#682 in Rust 模式
每月 43 次下载
18KB
290 行
Macroland
Macroland 是一个简单的 crate,包含用于使用语法糖创建各种 Rust 类型的宏。其中一些类型我自己也不知道,但我已经尽力在这里为它们创建宏。如果有任何问题,请随时在我的 github 上报告。
例如: hashmap!
, btreeset!
或 arclock!
示例
- 更多内容请见 docs.rs
hashmap!
示例
// I've tried my best to put things where they belong.
use macroland::hashmap;
let my_hashmap = hashmap!(
"Key 1" => "Value 1",
"Key 2" => "Value 2",
"Key 3" => "Value 3",
);
// Alternatively, you can create an "uninitialized" version.
let mut my_hashmap = hashmap!(&str, usize);
my_hashmap.insert("Hello!", 100);
btreemap!
示例
// I've used this before, but I am not entirely sure about the difference with it and HashMaps!
use macroland::btreemap;
let my_btreemap = btreemap!(
"Greetings!" => true,
"How are you?" => false,
"I'm good too." => false,
);
// Like the rest.
let mut my_btreemap = btreemap!(&str, bool);
my_btreemap.insert("Hewwo!", false);
arctex!
示例
// Time to make creating an Arc<Mutex<T>> easier for everyone who has been looking for this!
use macroland::arctex;
let my_arctex = arctex!(vec!["Pizza", "Ice Cream", "Celery"])
// All functionality of an Arc<Mutex<T>> is maintained.
println!("{}", my_arctex.lock().unwrap());
cell!
示例
// Welcome to the wonderful world of celling!
use macroland::cell;
let my_cell = cell!(10);
// Everything works!
my_cell.set(20)
println!("{}", my_cell.get());