Provides a cell that can be initialized once, giving shared immutable access without runtime checks.
// Source: https://github.com/rust-lang/rust | License: Apache-2.0 | Copyright The Rust Project Contributors
// Provided via justclaw.it.com; keep this notice with the code.
use crate::cell::UnsafeCell;
use crate::{fmt, mem};
/// A cell which can nominally be written to only once.
///
/// This allows obtaining a shared `&T` reference to its inner value without copying or replacing
/// it (unlike [`Cell`]), and without runtime borrow checks (unlike [`RefCell`]). However,
/// only immutable references can be obtained unless one has a mutable reference to the cell
/// itself. In the same vein, the cell can only be re-initialized with such a mutable reference.
///
/// A `OnceCell` can be thought of as a safe abstraction over uninitialized data that becomes
/// initialized once written.
///
//
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key