rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.02k stars 12.79k forks source link

Tracking Issue for `lazy_cell_into_inner` #125623

Open tspiteri opened 6 months ago

tspiteri commented 6 months ago

This superceded #109736 now that the lazy_cell feature has been stabilized.

Feature gate: #[feature(lazy_cell_into_inner)]

This is a tracking issue for LazyCell::into_inner and LazyLock::into_inner.

Public API

// core::cell (in core/src/cell/lazy.rs)

impl<T, F: FnOnce() -> T> LazyCell<T, F> {
    pub const fn into_inner(this: Self) -> Result<T, F>;
}
// std::sync (in std/sync/lazy_lock.rs)

impl<T, F: FnOnce() -> T> LazyLock<T, F> {
    pub fn into_inner(this: Self) -> Result<T, F>;
}

Steps / History

Unresolved Questions

workingjubilee commented 6 months ago

@tspiteri Would you be so kind as to make the tracking issue? (you could even just edit this one) We can edit it from there if we need to change things.

tgross35 commented 4 months ago

Could this be renamed to lazy_cell_into_inner? I keep thinking this is is referencing an API that uses atomic consume operations, which was discussed for the implementation of OnceLock/LazyLock but ultimately rejected (e.g. here).

workingjubilee commented 4 months ago

Go for it.

tgross35 commented 4 months ago

I was mostly asking for someone to rename the issue, but here we go https://github.com/rust-lang/rust/pull/127599. Rustbot has really been spot on picking reviewers for me recently.

tgross35 commented 22 hours ago

Could this be considered for stabilization? This serves the same purpose as into_inner methods available on other cell and sync types, and the signature is consistent with once_cell's Lazy::into_value.

The only downside I see here is that .unwrap() doesn't work since the closure doesn't implement Debug.

@rustbot label +I-libs-api-nominated