0

I am new to Rust. There is something I cannot understand about coercing. And also I am not sure how to name this issue, so forgive me for the bad title.

Here is a piece of codes that confuses me.

use std::ops::Deref;

struct myBox<T>(T);

impl<T> Deref for myBox<T>{
    type Target = T;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

fn is_equal0(a: &i32, b: &i32){
    println!("{}", a==b);
}

fn is_equal1(a: i32, b: i32){
    println!("{}", a==b);
}

fn main(){
    let a = myBox(myBox(100));
    let b = myBox(100);
    is_equal0(&100, &a); // (1.1) Why this statement could pass compilation? 
    is_equal0(&100, a); // (1.2) But this one fails ?
}
Herohtar
  • 4,958
  • 4
  • 31
  • 39

0 Answers0