Expand description
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);
Structs§
- Full
- Error type when stack array is full.
- Pointer
Array