Sugars - Nice Rust macros for better writing
This crate provides a collection of macros to make some tasks easier to use on Rust ecosystem.
What it has to offer?
- boxed: A simple macro to make a new Box value.
- btmap: Create a
BTreeMap
from a list of key-value pairs - btset: Create a
BTreeSet
from a list of elements - cmap: Macro to
HashMap
collection comprehensions¹ - cset: Macro to
HashSet
collection comprehensions¹ - cvec: Macro to
Vec
collection comprehensions¹ - dur: Creates a
Duration
object following a time pattern² - hmap: Create a
HashMap
from a list of key-value pairs - hset: Create a
HashSet
from a list of elements - sleep: Makes a thread sleep a amount following a time pattern²
- time: Print out the time it took to execute a given expression in seconds
- The comprehension macros supports a haskell-like as well as python-like writing syntax and have the limitation of not supporting nesting
- A time pattern can be: mim, sec, nano, micro, milli
Examples
boxed
assert_eq!;
hmap and btmap: Usage are the same, just change HashMap to BTreeMap and hmap! to btmap!
let mut map = new;
map.insert;
map.insert;
let map2 = hmap!;
assert_eq!;
hset and btset: Usage are the same, just change HashSet to BTreeSet and hset! to btset!
let mut set = new;
map.insert;
map.insert;
let set2 = hset!;
assert_eq!;
dur and sleep
let d1 = dur!;
let d2 = from_secs;
assert_eq!;
// Sleeps uses the same syntax, but makes the thread sleep for the given time
sleep!
cvec: Notice that cvec
can be nested up to 3 times max
// Normal comprehension
cvec!;
// You can filter as well
cvec!;
cset: Notice that cset
cannot be nested
// Normal comprehension
cset!;
// You can filter as well
cset!;
cmap: Notice that cmap
cannot be nested
// Normal comprehension
cmap!;
// You can filter as well
cmap!;
time
// Should print to stderr ≈ 2.0000 seconds
time!;
// It also return the evaluated expression, like dbg! macro
let x = time!;
LICENSE
This software is licensed under the MIT Public License.