,那 &"v 就相当于解出&T了; - 还有可能是v的type实现了Deref trait,那 &"v 就相当于调用 &"(v.deref())。 对于最后一种情况可以请参考我的博客 rust入门笔记 ..."> ,那 &"v 就相当于解出&T了; - 还有可能是v的type实现了Deref trait,那 &"v 就相当于调用 &"(v.deref())。 对于最后一种情况可以请参考我的博客 rust入门笔记 ...">

In 10 carts

Price: ₹ 261.000

Original Price: ₹ 541.000

50% off
New markdown! Biggest sale in 60+ days

Coercion: 不敢称大佬

You can only make an offer when buying a single item

Add to cart

不敢称大佬。 "v 说明v是可以 解引用 的. - 这里的解引用可能是的普通引用的解引用(这时的确t=v); - 也能可能v是一个裸指针, &"v 下来相当于把不安全的 裸指针 转换为普通的引用; - 也可能v是一个 智能指针,比如Bo,那 &"v 就相当于解出&T了; - 还有可能是v的type实现了Deref trait,那 &"v 就相当于调用 &"(v.deref())。 对于最后一种情况可以请参考我的博客 rust入门笔记 ... 结论是: 由于println!中只需要获取变量的不可变引用就可以了,因此不发生所有权转移。 更深入一下,Rust中哪些类型在什么时机会发生所有权转移呢,这是值得深入总结的问题。 引子 先从一个例子说起,看如下代码: The value of &T is forced to be converted to the value of &U. (deref coercion ). T implements all the (immutable) methods of U. The beauty of Deref is that it enhances the Rust development experience. A typical example from the standard library is that Vec shares all the methods of slice by implemented Deref. 的 hijacking of morality 那样明显贬义;在我的理解里,moral coercion 需要被制约限制,然而如果能使用恰当,也不失为一种倡导人行善的可行方法。 hijacking of morality 的意思是自称道德一方,将道德为己所用;然而这个“为己所用”可以是诱导民众,并不一定包括了“道德绑架”中的胁迫的意思。所以其实我觉得根据语境和需要强调的部分不同, moral coercion 和 hijacking of morality ...

4.9 out of 5

(32225 reviews)

5/5 Item quality
4/5 Shipping
4/5 Customer service
Loading