mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-29 11:37:39 +00:00
![]() Partial stabilization of `once_cell` This PR aims to stabilize a portion of the `once_cell` feature: - `core::cell::OnceCell` - `std::cell::OnceCell` (re-export of the above) - `std::sync::OnceLock` This will leave `LazyCell` and `LazyLock` unstabilized, which have been moved to the `lazy_cell` feature flag. Tracking issue: https://github.com/rust-lang/rust/issues/74465 (does not fully close, but it may make sense to move to a new issue) Future steps for separate PRs: - ~~Add `#[inline]` to many methods~~ #105651 - Update cranelift usage of the `once_cell` crate - Update rust-analyzer usage of the `once_cell` crate - Update error messages discussing once_cell ## To be stabilized API summary ```rust // core::cell (in core/cell/once.rs) pub struct OnceCell<T> { .. } impl<T> OnceCell<T> { pub const fn new() -> OnceCell<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceCell<T>; impl<T: Debug> Debug for OnceCell<T> impl<T> Default for OnceCell<T>; impl<T> From<T> for OnceCell<T>; impl<T: PartialEq> PartialEq for OnceCell<T>; impl<T: Eq> Eq for OnceCell<T>; ``` ```rust // std::sync (in std/sync/once_lock.rs) impl<T> OnceLock<T> { pub const fn new() -> OnceLock<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceLock<T>; impl<T: Debug> Debug for OnceLock<T>; impl<T> Default for OnceLock<T>; impl<#[may_dangle] T> Drop for OnceLock<T>; impl<T> From<T> for OnceLock<T>; impl<T: PartialEq> PartialEq for OnceLock<T> impl<T: Eq> Eq for OnceLock<T>; impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T>; unsafe impl<T: Send> Send for OnceLock<T>; unsafe impl<T: Sync + Send> Sync for OnceLock<T>; impl<T: UnwindSafe> UnwindSafe for OnceLock<T>; ``` No longer planned as part of this PR, and moved to the `rust_cell_try` feature gate: ```rust impl<T> OnceCell<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } impl<T> OnceLock<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } ``` I am new to this process so would appreciate mentorship wherever needed. |
||
---|---|---|
.. | ||
coverage | ||
inline | ||
abort_unwinding_calls.rs | ||
add_call_guards.rs | ||
add_moves_for_packed_drops.rs | ||
add_retag.rs | ||
check_const_item_mutation.rs | ||
check_packed_ref.rs | ||
check_unsafety.rs | ||
cleanup_post_borrowck.rs | ||
const_debuginfo.rs | ||
const_goto.rs | ||
const_prop_lint.rs | ||
const_prop.rs | ||
copy_prop.rs | ||
ctfe_limit.rs | ||
dataflow_const_prop.rs | ||
dead_store_elimination.rs | ||
deduce_param_attrs.rs | ||
deduplicate_blocks.rs | ||
deref_separator.rs | ||
dest_prop.rs | ||
dump_mir.rs | ||
early_otherwise_branch.rs | ||
elaborate_box_derefs.rs | ||
elaborate_drops.rs | ||
ffi_unwind_calls.rs | ||
function_item_references.rs | ||
generator.rs | ||
inline.rs | ||
instcombine.rs | ||
large_enums.rs | ||
lib.rs | ||
lower_intrinsics.rs | ||
lower_slice_len.rs | ||
match_branches.rs | ||
multiple_return_terminators.rs | ||
normalize_array_len.rs | ||
nrvo.rs | ||
pass_manager.rs | ||
remove_noop_landing_pads.rs | ||
remove_storage_markers.rs | ||
remove_uninit_drops.rs | ||
remove_unneeded_drops.rs | ||
remove_zsts.rs | ||
required_consts.rs | ||
reveal_all.rs | ||
separate_const_switch.rs | ||
shim.rs | ||
simplify_branches.rs | ||
simplify_comparison_integral.rs | ||
simplify.rs | ||
sroa.rs | ||
ssa.rs | ||
uninhabited_enum_branching.rs | ||
unreachable_prop.rs |