A HashVec is a hash map / dictionary whose key-value pairs are stored (and can be iterated over) in a fixed order, by default the order in which they were inserted into the map. It's essentially a vector whose values can be inserted/retrieved with keys.
```rust use hashvec::*;
// Create a new hashvec containing pairs of animal names and species // The hashvec! macro acts like vec!, but with key-value tuple pairs let mut hashvec: HashVec<&'static str, &'static str> = hashvec![ ("Doug", "Kobold"), ("Skye", "Hyena"), ("Lee", "Shiba"), ("Sock", "Man"), ("Salad", "Wolf"), ("Finn", "Human") ];
// Insert a value into the hashvec (HashMap-style) // Inserting overwrites existing keys' entries in-place hashvec.insert("Jake", "Dog");
// Push a value onto the hashvec (Vector-style) // Pushing overwrites existing keys' entries and moves them to the end hashvec.push(("Susie", "Squid"));
// Access a value by key match hashvec.get(&"Finn") { Some(value) => { assert_eq!(*value, "Human"); }, None => {} }
// Access an entry by index let leevalue = hashvec[2]; asserteq!(lee_value, ("Lee", "Shiba"));
// Get the index of a key let leeindex = hashvec.index(&"Lee").unwrap(); asserteq!(lee_index, 2);
// Get the length of the hashvec let hashveclength = hashvec.len(); asserteq!(hashvec_length, 8);
// Change an entry's key in-place hashvec.rename(&"Salad", "Caesar"); assert_eq!(hashvec[4], ("Caesar", "Wolf"));
// Mutate a value match hashvec.getmut(&"Sock") { Some(value) => { *value = "Guinea Pig"; }, None => {} } asserteq!(*hashvec.get(&"Sock").unwrap(), "Guinea Pig");
// Remove an entry hashvec.removekey(&"Doug"); asserteq!(hashvec.get(&"Doug"), None);
// Swap the locations of two entries by their keys hashvec.swapkeys(&"Lee", &"Skye"); asserteq!(hashvec.index(&"Lee").unwrap(), 0); assert_eq!(hashvec.index(&"Skye").unwrap(), 1);
// Now swap them again, by their indices hashvec.swapindices(0, 1); asserteq!(hashvec[0], ("Skye", "Hyena")); assert_eq!(hashvec[1], ("Lee", "Shiba"));
// Iterate over each of the key-value pairs in the hashvec for (k, v) in hashvec.into_iter() { println!("{} is a {}!", k, v); }
// Remove an entry from the end of the hashvec let lastentry = hashvec.pop(); asserteq!(last_entry.unwrap(), ("Susie", "Squid"));
// Clear the hashvec hashvec.clear(); ```