#[macro_use] extern crate data_structure_traits; #[cfg(feature = "hashmap_core")] extern crate hashmap_core; use std::collections::{BTreeMap, BTreeSet}; #[cfg(feature = "hashmap_core")] use hashmap_core::{FnvHashMap as HashMap, FnvHashSet as HashSet}; #[cfg(feature = "std")] use std::collections::{HashMap, HashSet}; use data_structure_traits::*; fn get(collection: &C, index: I) -> Option<&T> where C: Get, { collection.get(index) } fn len<'a, C>(c: &'a C) -> usize where C: 'a + Collection, { c.len() } #[test] fn test_get() { let vec: Vec = collection![0]; assert_eq!(get(&vec, 0), Some(&0)); let map: BTreeMap = collection!{0 => 0}; assert_eq!(get(&map, &0), Some(&0)); let map: HashMap = collection!{"0".into() => "0".into()}; assert_eq!(get(&map, "0"), Some(&String::from("0"))); let map: BTreeSet = collection!{0}; assert_eq!(get(&map, &0), Some(&0)); let map: HashSet = collection!{0}; assert_eq!(get(&map, &0), Some(&0)); } #[test] fn test_len() { let vec: Vec = collection![0, 1, 2, 3]; assert_eq!(len(&vec), 4); }