Visit the item as Pin

A preparation to have Property::get to take Pin<Self>
This commit is contained in:
Olivier Goffart 2020-06-25 18:50:20 +02:00
parent 40f4265071
commit 1b748792ad
8 changed files with 86 additions and 48 deletions

View file

@ -472,6 +472,18 @@ impl<Base, T: ?Sized + VTableMeta, Flag> VOffset<Base, T, Flag> {
}
}
impl<Base, T: ?Sized + VTableMeta> VOffset<Base, T, PinnedFlag> {
pub fn apply_pin<'a>(self, x: Pin<&'a Base>) -> Pin<VRef<'a, T>> {
let ptr = x.get_ref() as *const Base as *mut u8;
unsafe {
Pin::new_unchecked(VRef::from_raw(
NonNull::from(self.vtable),
NonNull::new_unchecked(ptr.add(self.offset)),
))
}
}
}
// Need to implement manually otheriwse it is not implemented if T do not implement Copy / Clone
impl<Base, T: ?Sized + VTableMeta, Flag> Copy for VOffset<Base, T, Flag> {}