pub fn borrow_as_box<T: Default, R, F: FnOnce(Box<T>) -> (R, Box<T>)>(
ptr: &mut T,
f: F,
) -> R
Expand description
Borrows a mutable reference as Box for the lifespan of this function.
Runs the given closure with the boxed value as a parameter. The closure is expected to return a boxed value, whose changes will be reflected on the mutable reference. Example:
use cairo_lang_utils::borrow_as_box;
let mut x = 5;
borrow_as_box(&mut x, |mut x: Box<usize>| {
*x += 1;
((), x)
});
assert_eq!(x, 6);