[英]Pin::as_mut(&mut self)
From the source forPin::as_mut
- pin.rs:来自Pin::as_mut
- pin.rs 的来源:
impl<P: DerefMut> Pin<P> {
...
pub fn as_mut(&mut self) -> Pin<&mut P::Target> {
unsafe { Pin::new_unchecked(&mut *self.pointer) }
}
...
}
I don't understand why &mut *self.pointer
is used instead of self.pointer
, What is wrong with the following sentence?我不明白为什么用&mut *self.pointer
代替self.pointer
,下面这句话有什么问题?
unsafe { Pin::new_unchecked(self.pointer) }
Pin::new_unchecked(self.pointer)
would just return a Pin<P>
instead of a Pin<&mut P::Target>
, deref coercions won't be considered. Pin::new_unchecked(self.pointer)
只会返回Pin<P>
而不是Pin<&mut P::Target>
,不会考虑 deref 强制。 It will also attempt to move pointer
out of self
and cause a compiler error.它还将尝试将pointer
移出self
并导致编译器错误。
Using *
will dereference self.pointer
into a P::Target
and &mut
makes it return a mutable reference.使用*
会将self.pointer
取消引用到P::Target
并且&mut
使它返回一个可变引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.