Why doesnt move occur when x is used to call abs function?

fn main() {
let x = Box::new(-1);
let x1 = i32::abs(*x); //explicit dereference
let x2 = x.abs(); //implicit dereference
assert_eq!(x1, x2);

let r = &x;
let r1 = i32::abs(**r);//abs(i32) so we need to dereference
let r2 = r.abs();//syntantic sugar
assert_eq!(x1, x2);

let s = String::from("Sabin");
let s1 = str::len(&s);
let s2 = s.len();
println!("{} {}", s1, s2);


Because primitive integers implement Copy.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.