Add the #[pin] attribute to be able to project to the pinned item

This commit is contained in:
Olivier Goffart 2020-06-25 12:17:32 +02:00
parent 9ed660926c
commit f50a705e00
9 changed files with 32 additions and 16 deletions

View file

@ -72,7 +72,7 @@ pub enum PinnedFlag {}
/// Type that can be used in the `Flag` parameter of `FieldOffset` to specify that
/// This projection is valid on Pin types.
type NotPinnedFlag = ();
pub type NotPinnedFlag = ();
/// `fn` cannot appear dirrectly in a type that need to be const.
/// Workaround that with an indiretion
@ -244,6 +244,11 @@ impl<T, U, Flag> FieldOffset<T, U, Flag> {
pub const unsafe fn as_pinned_projection(self) -> FieldOffset<T, U, PinnedFlag> {
FieldOffset::new_from_offset_pinned(self.get_byte_offset())
}
/// Remove the PinnedFlag
pub const fn as_unpinned_projection(self) -> FieldOffset<T, U> {
unsafe { FieldOffset::new_from_offset(self.get_byte_offset()) }
}
}
impl<T, U> FieldOffset<T, U, PinnedFlag> {