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
Unresolved Questions
Feature gate:
#![feature(once_cell_try_insert)]This is a tracking issue for
OnceCell::try_insert()andOnceLock::try_insert().This adds a method similarly to
OnceCell/Lock::set()but returns a reference at the same time. This is also similar toOnceCell/Lock::get_or_init()but the return value also tells you if the value was actually inserted or if theOnceCell/Lockwas already occupied.Public API
Steps / History
OnceCell/Lock::try_insert()libs-team#276OnceCell/Lock::try_insert()#116540Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩