anycollections
Rust Vec
and HashMap
which can contain arbitrary types inrernally casts inputs to Box<UnsafeAny>
.
AnyVec
```rust
extern crate anycollections;
use anycollections::AnyVec;
let mut v = TypeVec::new();
assert!(v.is_empty());
// Can push whatever values.
v.push(1);
v.push(2.2);
v.push("xxx");
v.push(vec![1, 2, 3]);
// Give type hint to specify return type.
asserteq!(v.get::(0), Some(&1));
asserteq!(v.get::(1), Some(&2.2));
asserteq!(v.get::<&str>(2), Some(&"xxx"));
asserteq!(v.get::>(3), Some(&vec![1, 2, 3]));
// getmut
asserteq!(v.get_mut::>(3), Some(&mut vec![1, 2, 3]));
// pop
asserteq!(v.pop::>(), Some(vec![1, 2, 3]));
asserteq!(v.pop::<&str>(), Some("xxx"));
asserteq!(v.pop::(), Some(2.2));
asserteq!(v.pop::(), Some(1));
```
AnyHashMap
```rust
extern crate anycollections;
use anycollections::AnyHashMap;
// Only to specify key type to create AnyHashMap
let mut m: AnyHashMap = AnyHashMap::new();
m.insert(10, 10);
m.insert(20, 22.2);
m.insert(30, "xxx");
m.insert(40, vec![1, 2, 3]);
// Give type hint to specify return type.
asserteq!(m.get::(&10), Some(&10));
asserteq!(m.get::(&20), Some(&22.2));
asserteq!(m.get::<&str>(&30), Some(&"xxx"));
asserteq!(m.get::>(&40), Some(&vec![1, 2, 3]));
asserteq!(m.getmut::(&10), Some(&mut 10));
asserteq!(m.getmut::(&20), Some(&mut 22.2));
asserteq!(m.getmut::<&str>(&30), Some(&mut "xxx"));
asserteq!(m.getmut::>(&40), Some(&mut vec![1, 2, 3]));
```