第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

鐵銹的自動解除規(guī)則是什么?

鐵銹的自動解除規(guī)則是什么?

鐵銹的自動解除規(guī)則是什么?我正在學習/試驗銹蝕,在我在這門語言中發(fā)現(xiàn)的所有優(yōu)雅中,有一個獨特之處讓我感到困惑,似乎完全不合適。在進行方法調(diào)用時,鐵銹自動取消指針。我做了一些測試來確定確切的行為:struct X { val: i32 }impl std::ops::Deref for X {    type Target = i32;    fn deref(&self) -> &i32 { &self.val }}trait            M                   { fn m(self); }impl             M for i32           { fn m(self) { println!("i32::m()"); } }impl             M for X             { fn m(self) { println!("X::m()"); } }impl<'a>         M for &'a X         { fn m(self) { println!("&X::m()"); } }impl<'a, 'b>     M for &'a &'b X     { fn m(self) { println!("&&X::m()"); } }impl<'a, 'b, 'c> M for &'a &'b &'c X { fn m(self) { println!("&&&X::m()"); } }trait            RefM                   { fn refm(&self); }impl             RefM for i32           { fn refm(&self) { println!("i32::refm()"); } }impl             RefM for X             { fn refm(&self) { println!("X::refm()"); } }impl<'a>         RefM for &'a X         { fn refm(&self) { println!("&X::refm()"); } }impl<'a, 'b>     RefM for &'a &'b X     { fn refm(&self) { println!("&&X::refm()"); } }impl<'a, 'b, 'c> RefM for &'a &'b &'c X { fn refm(&self) { println!("&&&X::refm()"); } }struct Y { val: i32 }impl std::ops::Deref for Y {    type Target = i32;    fn deref(&self) -> &i32 { &self.val }}struct Z { val: Y }impl std::ops::Deref for Z {    type Target = Y;    fn deref(&self) -> &Y { &self.val }}struct A;impl std::marker::Copy for A {}impl             M for             A { fn m(self) { println!("A::m()"); } }impl<'a, 'b, 'c> M for &'a &'b &'c A { fn m(self) { println!("&&&A::m()"); } }impl             RefM for             A { fn refm(&self) { println!("A::refm()"); } }impl<'a, 'b, 'c> RefM for &'a &'b &'c A { fn refm(&self) { println!("&&&A::refm()"); } }因此,似乎,或多或少:編譯器將插入調(diào)用方法所需的盡可能多的取消引用操作符。當解析使用&self(參照電話):第一次嘗試要求取消對self然后嘗試調(diào)用確切類型的self然后,嘗試插入匹配所需的盡可能多的取消引用操作符。方法聲明使用self(按值調(diào)用)類型T表現(xiàn)得好像他們是用&self(按引用調(diào)用)類型&T并調(diào)用對點運算符左側的任何內(nèi)容的引用。上面的規(guī)則首先嘗試使用原始內(nèi)置的反引用,如果沒有匹配,則使用Deref特質(zhì)被利用了。確切的自動取消引用規(guī)則是什么?有人能給出這樣一個設計決策的正式理由嗎?
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 477 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號