Open
Description
Feature gate: #![feature(once_cell_try_insert)]
This is a tracking issue for OnceCell::try_insert()
and OnceLock::try_insert()
.
This adds a method similarly to OnceCell/Lock::set()
but returns a reference at the same time. This is also similar to OnceCell/Lock::get_or_init()
but the return value also tells you if the value was actually inserted or if the OnceCell/Lock
was already occupied.
Public API
impl<T> OnceCell<T> {
pub fn try_insert(&self, value: T) -> Result<&T, (&T, T)>;
}
Steps / History
- ACP:
OnceCell/Lock::try_insert()
libs-team#276 - Implementation: Implement
OnceCell/Lock::try_insert()
#116540 - Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- None yet.