Skip to content

Commit 4746754

Browse files
committed
Add Lazy::get_unpin, spelling fixes
1 parent 65219fa commit 4746754

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/lib.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl Inner {
205205
// writes to the cell's value are visible to the cell's readers.
206206
let prev_state = self.state.fetch_or(READY_BIT, Ordering::Release);
207207

208-
debug_assert_eq!(prev_state & READY_BIT, 0, "Invalid state: somoene else set READY_BIT");
208+
debug_assert_eq!(prev_state & READY_BIT, 0, "Invalid state: someone else set READY_BIT");
209209
}
210210
}
211211

@@ -280,7 +280,7 @@ impl<'a> Drop for QuickInitGuard<'a> {
280280
let guard = waiter.guard.expect("No guard available even without polling");
281281
if guard.queue.is_null() {
282282
// The queue was already freed by someone else before we got our QueueRef (this must
283-
// have happend between the load of prev_state and initialize, because otherwise we
283+
// have happened between the load of prev_state and initialize, because otherwise we
284284
// would have taken the fast path). This implies that all other tasks have noticed
285285
// READY_BIT and do not need waking, so there is nothing left for us to do except
286286
// release our reference.
@@ -413,7 +413,7 @@ impl<T> OnceCell<T> {
413413
/// Gets the contents of the cell, initializing it with `init` if the cell was empty.
414414
///
415415
/// Many tasks may call `get_or_init` concurrently with different initializing futures, but
416-
/// it is guaranteed that only one future will be executed as long as the resuting future is
416+
/// it is guaranteed that only one future will be executed as long as the resulting future is
417417
/// polled to completion.
418418
///
419419
/// If `init` panics, the panic is propagated to the caller, and the cell remains uninitialized.
@@ -642,6 +642,20 @@ where
642642
}
643643
}
644644

645+
impl<T, F> Lazy<T, F>
646+
where
647+
F: Future<Output = T> + Unpin,
648+
{
649+
/// Forces the evaluation of this lazy value and returns a reference to the result.
650+
///
651+
/// Unlike [Self::get], this does not require pinning the object.
652+
pub async fn get_unpin(&self) -> &T {
653+
// The get() function itself does not use the fact that T is pinned, and Pin::deref already
654+
// exposes a &T from Pin<&T> (although not with the right lifetime).
655+
unsafe { Pin::into_inner_unchecked(Pin::new_unchecked(self).get().await) }
656+
}
657+
}
658+
645659
impl<T, F> Lazy<T, F> {
646660
/// Creates a new lazy value with the given initializing future.
647661
///

0 commit comments

Comments
 (0)