2 releases
0.1.1 | Apr 30, 2022 |
---|---|
0.1.0 | Apr 29, 2022 |
#14 in #type-id
12KB
236 lines
TypeId based pointer array.
lib.rs
:
An stack array store &T or &mut T as ([TypeId], *const/mut ()) Can be used to pass reference to function call when do not have full control of it's argument.
Example:
// a determined function that you can't modify for arbitrary argument.
fn bar(_arg1: (), mut arg2: PointerArray<'_>) {
// remove &mut Vec<String> from array.
let arg3 = arg2.remove_mut::<Vec<String>>().unwrap();
assert_eq!("arg3", arg3.pop().unwrap());
}
let ptr_array = PointerArray::new();
let mut arg3 = vec![String::from("arg3")];
// insert &mut Vec<String> to array. on Ok(_) the array itself would be returned with
// reference successfully inserted.
let ptr_array = ptr_array.insert_mut(&mut arg3).unwrap();
// pass the array as argument to bar.
bar((), ptr_array);