Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[inline(never)]
- fn borrows(input: &u32, output: &mut u32)
- {
- if *input > 10
- {
- *output = 2;
- }
- if *input > 5
- {
- *output *= 2;
- }
- }
- #[inline(never)]
- fn ptrs(input: *const u32, output: *mut u32)
- {
- unsafe
- {
- if *input > 10
- {
- *output = 2;
- }
- if *input > 5
- {
- *output *= 2;
- }
- }
- }
- #[inline(never)]
- fn mixed(input: *const u32, output: *mut u32)
- {
- let input = unsafe { &*input };
- let output = unsafe { &mut*output };
- if *input > 10
- {
- *output = 2;
- }
- if *input > 5
- {
- *output *= 2;
- }
- }
- fn main() {
- let borrows_value = 15;
- let ptrs_value = 15;
- let mixed_value = 15;
- borrows(&borrows_value, unsafe { &mut*(&borrows_value as *const _ as *mut _) });
- ptrs(&ptrs_value, &ptrs_value as *const _ as *mut _);
- mixed(&mixed_value, &mixed_value as *const _ as *mut _);
- dbg!(borrows_value);
- dbg!(ptrs_value);
- dbg!(mixed_value);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement