A dyamic resource storage written in rust. It supports storage of multiple types and multiple entries. It also supports dynamic borrow checking with the help of RefCell
s.
```rust use restor::DynamicStorage;
fn main() {
let mut storage = DynamicStorage::new();
storage.allocatefor::
storage.insert(0usize);
storage.insert_many(vec![1usize, 2, 3]);
storage.insert("abc".to_string());
for i in 0..4 {
let mut string_accquisition = storage.get_mut::<String>();
*string_accquisition = format!("{}, {}", &*string_accquisition, *storage.ind::<usize>(i));
}
assert_eq!(&*storage.get::<String>(), "abc, 0, 1, 2, 3");
} ```
BlackBox
(Or DynamicStorage
) is defined as so:
rust
struct BlackBox {
data: HashMap<TypeId, Box<dyn Unit>>
}
The Unit
trait allows us to abstract over the generic type of the container (Referred to as UnitStorage
in the code), so we can pass data in and out of it by using the seemingly magical Any
trait. When you insert something into the storage it goes through these stages:
1. Your data in BlackBox::insert<T>
2. Boxed into a Box<dyn Any>
3. Passed to the StorageUnit as dyn Unit
4. Try to downcast as either a T
or a Vec<T>
5. Pur inro its own place in the storage or in a Vec
Fn
to run on a piece of data or a sliceUnit
TypeId