Sugars - Nice Rust macros for better writing.
This crate provides a collection of useful macros to make tasks easier.
What it has to offer?
- Macros for
std::collections
: - Macros for
.collect()
comprehensions:- c: Macro to make lazy
Iterator
collection comprehensions, others below are based on this one. - cbheap: Build
BinaryHeap
with collection comprehensions. - cbtmap: Build
BTreeMap
with “ . - cbtset: Build
BTreeSet
with “ . - cdeque: Build
VecDeque
with “ . - cmap: Build
HashMap
with “ . - cset: Build
HashSet
with “ . - cvec: Build
Vec
with “ .
- c: Macro to make lazy
- Smart Pointers:
- Time/Duration:
- Returns a tuple if multiple parameters are given.
- Accepted time patterns are:
min
,sec
,nano
,micro
andmilli
.
Examples
std::collections
Usage of boxed
, same as arc
, cell
, cow
, mutex
and refcell
:
assert_eq!;
Usage of hmap
, same as btmap
:
let mut map = new;
map.insert;
map.insert;
map.insert;
let map2 = hmap! ;
assert_eq!;
Usage of hset
, same as btset
:
let set = hset! ;
let mut set2 = new;
set2.insert;
set2.insert;
set2.insert;
assert_eq!;
Usage of deque
, same as bheap
, lkl
and rlkl
:
let deque = deque!;
let mut deque2 = new;
deque2.push_back;
deque2.push_back;
deque2.push_back;
assert_eq!;
Comprenhensions
Usage of c!
: It follows the syntax: c![<expr>; <<pattern> in <iterator>, >...[, if <condition>]]
.
Note that it generates a lazy Iterator that needs to be dealt with.
let vec = c!.;
let set = c!.;
// A more complex one
let vec = c!.;
// Or using type hints
let vec: = c!.collect;
let set: = c!.collect;
let vec: = c!.collect;
Usage of cvec!
, same as cdeque!
, clkl!
and cbheap!
:
// Normal comprehension
cvec!;
// You can filter as well
cvec!;
Usage of cset
, same as cbtset
:
// Normal comprehension
cset! ;
// You can filter as well
cset! ;
Usage of cmap
, same as cbtmap
:
// Normal comprehension
cmap! ;
// You can filter as well
cmap! ;
Time/Duration:
Usage of dur
and sleep
:
let d1 = dur!;
let d2 = from_secs;
assert_eq!;
// Same syntax, but make the thread sleep for the given time
sleep!
Usage of 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.