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
Iteratorcollection comprehensions, others below are based on this one. - cbheap: Build
BinaryHeapwith collection comprehensions. - cbtmap: Build
BTreeMapwith “ . - cbtset: Build
BTreeSetwith “ . - cdeque: Build
VecDequewith “ . - cmap: Build
HashMapwith “ . - cset: Build
HashSetwith “ . - cvec: Build
Vecwith “ .
- c: Macro to make lazy
- Smart Pointers:
- Time/Duration:
- Returns a tuple if multiple parameters are given.
- Accepted time patterns are:
min,sec,nano,microandmilli.
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.