A memory storage comparable to a Vec where removing items doesn't shift all the items after the removed item to the left and doesn't invalidate their IDs. It allows you to remove items with high speed and access items via an ID that was returned after adding them.
``` use memorystorage::newwith_array;
let mut memorystorage = newwith_array::
let idofone = memorystorage.insert(1) .expect("Something went wrong!"); let idoftwo = memorystorage.insert(2) .expect("Something went wrong!"); let idofthree = memory_storage.insert(3) .expect("Something went wrong!");
// We are at max capacity! assert!(memorystorage.insert(4).iserr());
let two = memorystorage.remove(idoftwo); let idoffour = memorystorage.insert(4) .expect("Something went wrong!"); let three = *memorystorage.get(idof_three) .expect("Something went wrong!");
assert_eq!(three, 3); ```
``` // Only with 'alloc' feature on! use memorystorage::vec::newwithfixedcapacityvec; use memorystorage::vec::newwithvec;
// Create a MemoryStorage using a vec with a fixed size of 3. let fixedsizevecmemorystorage = newwithfixedcapacityvec::<()>(3);
// MemoryStorage using a vec allowing to allocate more space. // Here we create an instance with the size of 1 (which can be increased). let mut vecmemorystorage = newwithvec(1);
let idofone = vecmemorystorage.push(1); let idoftwo = vecmemorystorage.push(2); let idofthree = vecmemorystorage.push(3);
let three = *vecmemorystorage.get(idofthree) .expect("Something went wrong!");
assert_eq!(three, 3); ```