#map #set #operator #easy #collection

easy_collections

Wrappers around standard collections for ease of use and quick prototyping

6 releases

0.3.2 Jan 3, 2021
0.3.1 Jan 3, 2021
0.2.0 Jan 2, 2021
0.1.1 Dec 31, 2020

#454 in Data structures

Download history 12/week @ 2021-01-16 6/week @ 2021-01-23 1/week @ 2021-01-30 15/week @ 2021-02-06 52/week @ 2021-02-13 7/week @ 2021-02-20 6/week @ 2021-02-27 2/week @ 2021-03-06 3/week @ 2021-03-13 15/week @ 2021-03-20 14/week @ 2021-03-27 8/week @ 2021-04-03 41/week @ 2021-04-10 8/week @ 2021-04-17 6/week @ 2021-04-24 9/week @ 2021-05-01

71 downloads per month
Used in ftrace

Unlicense OR MIT OR Apache-2.0

25KB
478 lines

crate documentation Average time to resolve an issue Percentage of issues still open

easy_collections

These are wrappers around HashSet and HashMap which make them a little more convenient to use. They aren't intended for use in main applications, but were created to make prototyping and writing short programs easier.

Usage

The struct EasySet wraps HashSet with some useful trait implementations.

use easy_collections::set;

let a = &set!{1, 2, 3};
let b = &set!{2, 3, 4};
assert_eq!(a & b, set!{2, 3});        // intersection
assert_eq!(a | b, set!{1, 2, 3, 4});  // union
assert_eq!(a ^ b, set!{1, 4});        // symmetric difference
assert_eq!(a - b, set!{1});           // difference

let c = &set!{1, 2, 3, 4};
assert!(a < c && b < c);              // subset
assert!(c > a && c > b);              // superset
assert!(*a == set!{1, 2, 3});         // equality

The struct EasyMap wraps HashMap with some useful trait implementations.

use easy_collections::{EasyMap, map};

// `42` here is the default value which is returned when no item exists in the map
// The default value is optional.
let map = map!{42; ("foo", 1), ("bar", 10), ("baz", 100)};
assert_eq!(map["foo"], 1);
assert_eq!(map["bar"], 10);
assert_eq!(map["baz"], 100);
assert_eq!(map["nope"], 42);
assert_eq!(map["nada"], 42);
assert_eq!(map["nuttin'"], 42);

// If you want to create a map with just a single value, and no default, use a trailing comma:
let map: EasyMap<&str, (&str, &str)> = map!{("foo", "bar")};
let map: EasyMap<&str, &str> = map!{("foo", "bar"),};

Also, both EasyMap and EasySet deref to their underlying collections, for example:

use std::collections::{HashMap, HashSet};
use easy_collections::{EasyMap, EasySet, map, set};

let easy: EasySet<_> = set!{"foo", "bar"};
let hash: &HashSet<_> = &*easy;
assert_eq!(&*easy, hash);

let easy: EasyMap<_, _> = map!{("foo", "bar"),};
let hash: &HashMap<_, _> = &*easy;
assert_eq!(&*easy, hash);

License: Unlicense OR MIT OR Apache-2.0

Dependencies