{"id":17084399,"url":"https://github.com/niklasf/double-checked-cell","last_synced_at":"2025-04-12T21:10:35.897Z","repository":{"id":52413082,"uuid":"109261930","full_name":"niklasf/double-checked-cell","owner":"niklasf","description":"A thread-safe lazily initialized cell using double-checked locking.","archived":false,"fork":false,"pushed_at":"2022-12-26T14:54:05.000Z","size":52,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T09:49:33.755Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/niklasf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-02T12:28:37.000Z","updated_at":"2024-02-11T00:27:37.000Z","dependencies_parsed_at":"2023-01-31T00:21:44.119Z","dependency_job_id":null,"html_url":"https://github.com/niklasf/double-checked-cell","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Fdouble-checked-cell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Fdouble-checked-cell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Fdouble-checked-cell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niklasf%2Fdouble-checked-cell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niklasf","download_url":"https://codeload.github.com/niklasf/double-checked-cell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631676,"owners_count":21136562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T13:07:02.741Z","updated_at":"2025-04-12T21:10:35.875Z","avatar_url":"https://github.com/niklasf.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"double-checked-cell\n===================\n\nA thread-safe lazily initialized cell using double-checked locking.\n\n[![Build Status](https://travis-ci.org/niklasf/double-checked-cell.svg?branch=master)](https://travis-ci.org/niklasf/double-checked-cell)\n[![crates.io](https://img.shields.io/crates/v/double-checked-cell.svg)](https://crates.io/crates/double-checked-cell)\n[![docs.rs](https://docs.rs/double-checked-cell/badge.svg)](https://docs.rs/double-checked-cell)\n[![No maintenance intended](https://img.shields.io/badge/no%20maintenance%20intended-x-red.svg)](https://github.com/rust-lang/rust/issues/74465)\n\nDeprecated\n----------\n\nYou should probably use [once_cell](https://crates.io/crates/once_cell) instead of this crate.\nIt provides a superset of this crate's functionality, with a nicely consistent API.\nIts functionality is also being considered for [inclusion in the standard library](https://github.com/rust-lang/rust/issues/74465).\n\nIntroduction\n------------\n\nProvides a memory location that can be safely shared between threads and\ninitialized at most once. Once the cell is initialized it becomes immutable.\n\nIf you do not need to change the value after initialization\n`DoubleCheckedCell\u003cT\u003e` is more efficient than a `Mutex\u003cOption\u003cT\u003e\u003e`.\n\n```rust\nextern crate double_checked_cell;\n\nuse double_checked_cell::DoubleCheckedCell;\n\nfn main() {\n    let cell = DoubleCheckedCell::new();\n\n    // The cell starts uninitialized.\n    assert_eq!(cell.get(), None);\n\n    // Perform potentially expensive initialization.\n    let value = cell.get_or_init(|| 21 + 21);\n    assert_eq!(*value, 42);\n    assert_eq!(cell.get(), Some(\u002642));\n\n    // The cell is already initialized.\n    let value = cell.get_or_init(|| unreachable!());\n    assert_eq!(*value, 42);\n    assert_eq!(cell.get(), Some(\u002642));\n}\n```\n\nRelated crates\n--------------\n\n* [once_cell](https://crates.io/crates/once_cell) – See above.\n\nThese crates are similar but distinct by design:\n\n* [lazy-init](https://crates.io/crates/lazy-init) – Based on a `LazyTransform\u003cT, U\u003e` which can lazily consume `T` to produce an `U`. Therefore cannot support fallible initialization.\n* [lazycell](https://crates.io/crates/lazycell) – `AtomicLazyCell` does not support lazy initialization (unlike its non-thread-safe counterpart `LazyCell` using `LazyCell::borrow_with()`).\n* [mitochondria](https://crates.io/crates/mitochondria) – Not `Sync`.\n* [lazy_static](https://crates.io/crates/lazy_static) - With the optional (currently nightly only) `const_fn` feature, `DoubleCheckedCell::new()` can also be used in static/const context. However `lazy_static!` is more convenient when there is only a single way to initialize the cell.\n\nDocumentation\n-------------\n\n[Read the documentation](https://docs.rs/double-checked-cell)\n\nChangelog\n---------\n\n* 2.1.0\n  - Fix `UnwindSafe` and `RefUnwindSafe` bounds. This is technically a breaking\n    change, but published under the same major version because it is a bugfix.\n* 2.0.3\n  - Update to parking_lot 0.11.\n* 2.0.2\n  - Update to parking_lot 0.9.\n* 2.0.1\n  - Update to parking_lot 0.7.\n* 2.0.0\n  - Changed unwinding behavior: `DoubleCheckedCell` no longer implements\n    poisoning.\n  - New optional cargo features: `parking_lot_mutex`, `const_fn`.\n* 1.1.0\n  - Fix unsoundness: `DoubleCheckedCell\u003cT\u003e` where `T: !Send` cannot be `Sync`.\n* 1.0.1\n  - Ignore `unused_unsafe` warning due to `UnsafeCell::into_inner()` no longer\n    beeing unsafe.\n* 1.0.0\n  - Initial release.\n\nLicense\n-------\n\ndouble-checked-cell is licensed under the [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0)\nand [MIT](http://opensource.org/licenses/MIT) license, at your option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklasf%2Fdouble-checked-cell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniklasf%2Fdouble-checked-cell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniklasf%2Fdouble-checked-cell/lists"}