Sugars - Nice Rust macros for better writing

Documentation Github Actions Build Status License Hits-of-Code

This crate provides a collection of macros to make some tasks easier to use on Rust ecosystem.

What it has to offer?

Examples

arc, boxed, cell, cow, mutex and refcell: Usage are mostly the same, just change de Types and macros rust assert_eq!(Box::new(10), boxed!(10));

hmap and btmap: Usage are the same, just change HashMap to BTreeMap and hmap! to btmap! ```rust let mut map = HashMap::new(); map.insert("1", 1); map.insert("2", 2);

let map2 = hmap!{"1" => 1, "2" => 2};

assert_eq!(map, map2); ```

hset and btset: Usage are the same, just change HashSet to BTreeSet and hset! to btset! ```rust let mut set = HashSet::new(); map.insert(1); map.insert(2);

let set2 = hset!{1, 2};

assert_eq!(set, set2); ```

dur and sleep ```rust let d1 = dur!(10 sec); let d2 = Duration::from_secs(10);

assert_eq!(d1, d2);

// Sleeps uses the same syntax, but makes the thread sleep for the given time sleep!(10 sec) ```

cvec: Notice that cvec can be nested up to 3 times max ```rust // Normal comprehension cvec![x | x <- 0..10];

// You can filter as well cvec![x | x <- 0..10, if x % 2 == 0]; ```

cset and cbtset: Notice that cset/cbtset cannot be nested. Usage are the same, just change HashSet to BTreeSet and cset! to cbtset! ```rust // Normal comprehension cset!{x | x <- 0..10};

// You can filter as well cset!{x | x <- 0..10, if x % 2 == 0}; ```

cmap and cbtmap: Notice that cmap/cbtmap cannot be nested. Usage are the same, just change HashMap to BTreeMap and cmap! to cbtmap! ```rust // Normal comprehension cmap!{x => x*2 | x <= x <- 1..10};

// You can filter as well cmap!{x => x*2 | x <= x <- 1..10, if x%2 == 0}; ```

time ```rust // Should print to stderr ≈ 2.0000 seconds time!( sleep!(2 sec) );

// It also return the evaluated expression, like dbg! macro let x = time!( 100 + 20 ); ```

Minimal Viable Rust Version

This software requires Rust version equal or above 1.38.

LICENSE

This software is licensed under the MIT Public License.