A dyamic resource storage written in rust. It supports storage of multiple types and multiple entries and dynamic borrow checking with the help of RefCell
s, Mutex
s and RwLock
s from parking_lot
.
```rust use restor::{DynamicStorage, make_storage};
fn main() {
let x = makestorage!(DynamicStorage: usize, String);
x.insertmany(vec![2usize; 20]).unwrap();
x.insert("abc".tostring()).unwrap();
let mut mystring = x.getmut::
BlackBox
(Or DynamicStorage
) is defined as so (More or less):
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. Put into its own place in the storage or in a Vec
FnMut(&[T])
to run on a piece of data or a sliceFnMut(&mut[T])
to run on a piece of data or a sliceUnit
try_*
functionsTypeId