Example about: i32 ref and i32 owned in fns?

⚓ Rust    📅 2026-02-23    👤 surdeus    👁️ 2      

surdeus

// E1:
//..
pub fn _new(v  :&i32)->Self{
    let ptr: *const i32 = v; // ref argument
    Self(v,ptr)
}
//...
//E2:
///..
pub fn _new(v :i32)->Self{
    let ptr: *const i32 = &v;  // owned argument
    Self(v,ptr)
}
//...

E1:Compiler Explorer
E2:Compiler Explorer

Question: In fn (self),Is

fn(self)->*const Self{ &self as *const i32} == fn(&self)->*const Self{ self as *const i32} 

?

1 post - 1 participant

Read full topic

🏷️ Rust_feed