Skip to content

Commit 956238e

Browse files
m-ou-seMark-Simulacrum
authored andcommitted
Add Pin::new_static.
1 parent 93ba97f commit 956238e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/core/src/pin.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,19 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
781781
}
782782
}
783783

784+
impl<T: ?Sized> Pin<&'static T> {
785+
/// Get a pinned reference from a static reference.
786+
///
787+
/// This is safe, because the `'static` lifetime guarantees the data will
788+
/// never be moved.
789+
#[unstable(feature = "pin_static_ref", issue = "none")]
790+
pub fn new_static(r: &'static T) -> Pin<&'static T> {
791+
// SAFETY: The 'static lifetime guarantees the data will not be
792+
// moved/invalidated until it gets dropped (which is never).
793+
unsafe { Pin::new_unchecked(r) }
794+
}
795+
}
796+
784797
#[stable(feature = "pin", since = "1.33.0")]
785798
impl<P: Deref> Deref for Pin<P> {
786799
type Target = P::Target;

0 commit comments

Comments
 (0)