too-many-lists/production-unsafe-deque/variance-and-phantomData #1360
Replies: 4 comments
-
这一节是翻译的吧?感觉读起来怪怪的 |
Beta Was this translation helpful? Give feedback.
-
即使是知道协变,逆变,抗变这几个概念的,我觉得这章都看的一头雾水... |
Beta Was this translation helpful? Give feedback.
-
这章看完了,但是没看 |
Beta Was this translation helpful? Give feedback.
-
感觉这里原作者讲的有点问题,简短的说一下个人理解: 重点是: 实际上,对于类型'a和T,可变引用&'a mut T是一种二元映射。 也就是说,严格来说,文中说&mut T是不变的,这句话是不对的,或者说不严格的,应当理解为&'a mut T关于T是不变的。这一部分感觉算是Rust类型论方面的理论。 顺带一提PhantomData似乎也是关于T协变的,理由是下面的代码可以编译通过: use std::marker::PhantomData;
fn phantom_data<'short, 'long: 'short>(long: PhantomData<&'long i32>) -> PhantomData<&'short i32> {
long
} 关于型变,The Rustonomicon中总结了如下表格:
具体可见:https://doc.rust-lang.org/nightly/nomicon/subtyping.html |
Beta Was this translation helpful? Give feedback.
-
too-many-lists/production-unsafe-deque/variance-and-phantomData
https://course.rs/too-many-lists/production-unsafe-deque/variance-and-phantomData.html
Beta Was this translation helpful? Give feedback.
All reactions