Skip to content

Commit 15d2f96

Browse files
committed
Add Option::as_pin_mut
1 parent b7ccb24 commit 15d2f96

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#![deny(missing_debug_implementations)]
7575

7676
#![feature(allow_internal_unstable)]
77+
#![feature(arbitrary_self_types)]
7778
#![feature(asm)]
7879
#![feature(associated_type_defaults)]
7980
#![feature(attr_literals)]

src/libcore/option.rs

+10
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147

148148
use iter::{FromIterator, FusedIterator, TrustedLen};
149149
use {mem, ops};
150+
use mem::PinMut;
150151

151152
// Note that this is not a lang item per se, but it has a hidden dependency on
152153
// `Iterator`, which is one. The compiler assumes that the `next` method of
@@ -269,6 +270,15 @@ impl<T> Option<T> {
269270
}
270271
}
271272

273+
/// Converts from `Option<T>` to `Option<PinMut<'_, T>>`
274+
#[inline]
275+
#[unstable(feature = "pin", issue = "49150")]
276+
pub fn as_pin_mut<'a>(self: PinMut<'a, Self>) -> Option<PinMut<'a, T>> {
277+
unsafe {
278+
PinMut::get_mut(self).as_mut().map(|x| PinMut::new_unchecked(x))
279+
}
280+
}
281+
272282
/////////////////////////////////////////////////////////////////////////
273283
// Getting to contained values
274284
/////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)