What's the type of the 'self' of "&&&T.SomeFunction(&self)" when “impl<T> SomeFunction for &&T”?

Viewed 39
#[derive(Debug)]
struct Rectangle {
    width: u32,
    height: u32,
}

impl Copy for Rectangle {}
impl Clone for Rectangle {
    fn clone(&self) -> Self {
        *self
    }
}

trait Ryx {
    fn call_ryx(&self);
}
trait WTL {
    fn call_wtl(&self);
}
impl<T> WTL for &T {
    fn call_wtl(&self) {
        println!("{}",String::from("I am call wtl"));
    }
}
impl<T> Ryx for &&T {
    fn call_ryx(&self) {
        println!("{}",String::from("I am call ryx"));
    }
}
#[test]
fn test_self() {
    let mut r = Rectangle{width:1,height:2};
    let ss = &r;
    ss.call_wtl(); // self:*mut *mut Rectangle   for &T
    //ss.call_ryx(); error for &&T
    let ss = &&r;
    ss.call_wtl(); // self:*mut *mut Rectangle   for &T
    ss.call_ryx(); // self:*mut *mut *mut Rectangle  for &&T

    let ss = &&&r;
    ss.call_wtl(); // self:*mut *mut *mut Rectangle  for &T
    ss.call_ryx(); // self:*mut *mut *mut Rectangle  for &&T

    let ss = &&&&r;
    ss.call_wtl(); // self:*mut *mut *mut *mut Rectangle for &T
    ss.call_ryx(); // self:*mut *mut *mut *mut Rectangle for &&T

    println!("{:?}",ss);
}

When I was debugging the functions call_wtl and call_ryx , I'm confused about what type of "self" should be in the functions. I guess self is the type of " *mut ... Rectangle " (*mut numbers equals "&" numbers) if the numbers of "&" are more than numbers of "&" of "impl Ryx for &&T" Anyone can explain the regulars about these?

0 Answers
Related