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?
- Collections:
- bheap: Create a
BinaryHeapfrom a list of key-value pairs - btmap: Create a
BTreeMapfrom a list of key-value pairs - btset: Create a
BTreeSetfrom a list of elements - deque: Create a
VecDequefrom a list of elements - 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.
- bheap: Create a
- Comprehensions:
- c: Macro to make a lazy Iterator collection comprehensions, all other are base on this one.
- cbheap: Macro to
BinaryHeapcollection comprehensions - cbtmap: Macro to
BTreeMapcollection comprehensions - cbtset: Macro to
BTreeSetcollection comprehensions - cdeque: Macro to
VecDequecollection comprehensions - cmap: Macro to
HashMapcollection comprehensions - cset: Macro to
HashSetcollection comprehensions - cvec: Macro to
Veccollection comprehensions
- Smart Pointers:
- arc: A simple macro to make a new
Arcvalue.² - boxed: A simple macro to make a new
Boxvalue.² - cell: A simple macro to make a new
Cellvalue.² - cow: A simple macro to make a new
Cowvalue. - 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.² - rwlock: A simple macro to make a new [
RwLock] value.²
- arc: A simple macro to make a new
- Time/Duration:
- dur: Creates a
Durationobject following a time pattern¹ - 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
- dur: Creates a
- 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 de Types and macros
let mut map = new;
map.insert;
map.insert;
let map2 = hmap!;
assert_eq!;
bheap, hset, btset and deque: Usage are the same, just change de Types and macros
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!
c: Notice that it generates a lazy Iterator, so the user has to deal with that
This has the following syntax: c![<expr>; <<pattern> in <iterator>, >...[, if <condition>]]
c!.;
c!.;
c!.;
cvec, cdeque, clkl and cbheap: Usage are the same, just change de Types and macros
// Normal comprehension
cvec!;
// You can filter as well
cvec!;
cset and cbtset: Usage are the same, just change de Types and macros
// Normal comprehension
cset!;
// You can filter as well
cset!;
cmap and cbtmap: Usage are the same, just change de Types and macros
// 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.39.0.
LICENSE
This software is licensed under the MIT Public License.