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?
- arc: A simple macro to make a new
Arcvalue.³ - boxed: A simple macro to make a new
Boxvalue.³ - btmap: Create a
BTreeMapfrom a list of key-value pairs - btset: Create a
BTreeSetfrom a list of elements - cbtmap: Macro to
BTreeMapcollection comprehensions¹ - cbtset: Macro to
BTreeSetcollection comprehensions¹ - cell: A simple macro to make a new
Cellvalue.³ - cmap: Macro to
HashMapcollection comprehensions¹ - cow: A simple macro to make a new
Cow::Ownedvalue. - cset: Macro to
HashSetcollection comprehensions¹ - cvec: Macro to
Veccollection comprehensions¹ - dur: Creates a
Durationobject following a time pattern² - flkl: Create a
LinkedListfrom a list of elements, adding each element to the start of the list. - hmap: Create a
HashMapfrom a list of key-value pairs - hset: Create a
HashSetfrom a list of elements - lkl: Create a
LinkedListfrom a list of elements, adding each element to the end of the list. - mutex: A simple macro to make a new
Mutexvalue.³ - refcell: A simple macro to make a new
RefCellvalue.³ - rc: A simple macro to make a new
Rcvalue.³ - 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
- Also can return a tuple if is given more than one parameter
Examples
arc, boxed, cell, cow, mutex and refcell: Usage are mostly the same, just change de Types and macros
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 and cbtset: Notice that cset/cbtset cannot be nested. Usage are the same, just change HashSet to BTreeSet and cset! to cbtset!
// Normal comprehension
cset!;
// You can filter as well
cset!;
cmap and cbtmap: Notice that cmap/cbtmap cannot be nested. Usage are the same, just change HashMap to BTreeMap and cmap! to cbtmap!
// 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!;
Minimal Viable Rust Version
This software requires Rust version equal or above 1.38.
LICENSE
This software is licensed under the MIT Public License.