This crate provides a collection of macros to make some tasks easier to use on Rust ecosystem.
BinaryHeap
from a list of key-value pairsBTreeMap
from a list of key-value pairsBTreeSet
from a list of elementsVecDeque
from a list of elementsLinkedList
from a list of elements, adding each element to the start of the list.HashMap
from a list of key-value pairsHashSet
from a list of elementsLinkedList
from a list of elements, adding each element to the end of the list.BinaryHeap
collection comprehensionsBTreeMap
collection comprehensionsBTreeSet
collection comprehensionsVecDeque
collection comprehensionsHashMap
collection comprehensionsHashSet
collection comprehensionsVec
collection comprehensionsArc
value.²Box
value.²Cell
value.²Cow
value.Mutex
value.²RefCell
value.²Rc
value.²RwLock
] value.²Time/Duration:
Duration
object following a time pattern¹A time pattern can be: mim, sec, nano, micro, milli
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 de Types and macros ```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); ```
bheap, hset, btset and deque: Usage are the same, just change de Types and macros ```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) ```
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>]]
rust
c![x; x in 0..10].collect::<Vec<_>>();
c![i*2; &i in vec.iter()].collect::<HashSet<_>>();
c![i+j; i in vec1.into_iter(), j in vec2.into_iter(), if i%2 == 0 && j%2 != 0].collect::<Vec<_>>();
cvec, cdeque, clkl and cbheap: Usage are the same, just change de Types and macros ```rust // Normal comprehension cvec![x; x in 0..10];
// You can filter as well cvec![x; x in 0..10, if x % 2 == 0]; ```
cset and cbtset: Usage are the same, just change de Types and macros ```rust // Normal comprehension cset!{x; x in 0..10};
// You can filter as well cset!{x; x in 0..10, if x % 2 == 0}; ```
cmap and cbtmap: Usage are the same, just change de Types and macros ```rust // Normal comprehension cmap!{x => x*2; x in 1..10};
// You can filter as well cmap!{x => x*2; x in 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 ); ```
This software requires Rust version equal or above 1.39.0.
This software is licensed under the MIT Public License.