Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions library/core/src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,34 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
}
}

impl<T: ?Sized> Pin<&'static T> {
/// Get a pinned reference from a static reference.
///
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
/// never ends.
#[unstable(feature = "pin_static_ref", issue = "none")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
pub const fn static_ref(r: &'static T) -> Pin<&'static T> {
// SAFETY: The 'static borrow guarantees the data will not be
// moved/invalidated until it gets dropped (which is never).
unsafe { Pin::new_unchecked(r) }
}
}

impl<T: ?Sized> Pin<&'static mut T> {
/// Get a pinned mutable reference from a static mutable reference.
///
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
/// never ends.
#[unstable(feature = "pin_static_ref", issue = "none")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
// SAFETY: The 'static borrow guarantees the data will not be
// moved/invalidated until it gets dropped (which is never).
unsafe { Pin::new_unchecked(r) }
}
}

#[stable(feature = "pin", since = "1.33.0")]
impl<P: Deref> Deref for Pin<P> {
type Target = P::Target;
Expand Down