Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn example2(x: &i32, f: impl FnOnce(&i32)) -> i32 {
- let val = *x / 3;
- f(x);
- return *x / 3; // We want to optimize this to return `val`.
- }
- fn main() {
- let mut local = 6;
- let x = &local;
- let result = example2(x, |inner_x| {
- let raw_pointer = inner_x as *const i32 as *mut i32;
- unsafe { *raw_pointer = 15; }
- });
- println!("{}", result); // Prints "5" (aka 15/3).
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement