Skip to content

Commit 4b35912

Browse files
Add core::sync::SyncView<T: Sync>::as_pin
This completes the existing suite of `as_ref`, `as_mut`, and `as_pin_mut` methods.
1 parent b360620 commit 4b35912

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

library/core/src/sync/sync_view.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,24 @@ impl<T: ?Sized> SyncView<T> {
177177
}
178178
}
179179

180+
impl<T: ?Sized + Sync> SyncView<T> {
181+
/// Gets pinned shared access to the underlying value.
182+
///
183+
/// `SyncView` is considered to _structurally pin_ the underlying
184+
/// value, which means _unpinned_ `SyncView`s can produce _unpinned_
185+
/// access to the underlying value, but _pinned_ `SyncView`s only
186+
/// produce _pinned_ access to the underlying value.
187+
#[unstable(feature = "exclusive_wrapper", issue = "98407")]
188+
#[rustc_const_unstable(feature = "exclusive_wrapper", issue = "98407")]
189+
#[must_use]
190+
#[inline]
191+
pub const fn as_pin(self: Pin<&Self>) -> Pin<&T> {
192+
// SAFETY: `SyncView` can only produce `&T` if itself is unpinned
193+
// `Pin::map_unchecked` is not const, so we do this conversion manually
194+
unsafe { Pin::new_unchecked(&self.get_ref().inner) }
195+
}
196+
}
197+
180198
#[unstable(feature = "exclusive_wrapper", issue = "98407")]
181199
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
182200
impl<T> const From<T> for SyncView<T> {

0 commit comments

Comments
 (0)