Function cairo_lang_utils::borrow_as_box
source · 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);