{"id":13484803,"url":"https://github.com/matklad/once_cell","last_synced_at":"2025-05-14T08:05:15.724Z","repository":{"id":39613545,"uuid":"143220272","full_name":"matklad/once_cell","owner":"matklad","description":"Rust library for single assignment cells and lazy statics without macros","archived":false,"fork":false,"pushed_at":"2025-03-28T17:16:00.000Z","size":518,"stargazers_count":1971,"open_issues_count":2,"forks_count":115,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-14T08:03:58.281Z","etag":null,"topics":["lazy-evaluation","rust"],"latest_commit_sha":null,"homepage":"","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/matklad.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-08-02T00:00:59.000Z","updated_at":"2025-05-12T21:39:13.000Z","dependencies_parsed_at":"2023-02-01T03:31:09.840Z","dependency_job_id":"806d0012-5e72-4edf-93bb-51e5188fb856","html_url":"https://github.com/matklad/once_cell","commit_stats":{"total_commits":342,"total_committers":53,"mean_commits":6.452830188679245,"dds":"0.45906432748538006","last_synced_commit":"4fbd4a53509ca59c8e09efc2ab0a22f21de70f7e"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matklad%2Fonce_cell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matklad%2Fonce_cell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matklad%2Fonce_cell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matklad%2Fonce_cell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matklad","download_url":"https://codeload.github.com/matklad/once_cell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101588,"owners_count":22014907,"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":["lazy-evaluation","rust"],"created_at":"2024-07-31T17:01:34.119Z","updated_at":"2025-05-14T08:05:15.706Z","avatar_url":"https://github.com/matklad.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"design/logo.png\" alt=\"once_cell\"\u003e\u003c/p\u003e\n\n\n[![Build Status](https://github.com/matklad/once_cell/actions/workflows/ci.yaml/badge.svg)](https://github.com/matklad/once_cell/actions)\n[![Crates.io](https://img.shields.io/crates/v/once_cell.svg)](https://crates.io/crates/once_cell)\n[![API reference](https://docs.rs/once_cell/badge.svg)](https://docs.rs/once_cell/)\n\n# Overview\n\n`once_cell` provides two new cell-like types, `unsync::OnceCell` and `sync::OnceCell`. `OnceCell`\nmight store arbitrary non-`Copy` types, can be assigned to at most once and provide direct access\nto the stored contents. In a nutshell, API looks *roughly* like this:\n\n```rust\nimpl OnceCell\u003cT\u003e {\n    fn new() -\u003e OnceCell\u003cT\u003e { ... }\n    fn set(\u0026self, value: T) -\u003e Result\u003c(), T\u003e { ... }\n    fn get(\u0026self) -\u003e Option\u003c\u0026T\u003e { ... }\n}\n```\n\nNote that, like with `RefCell` and `Mutex`, the `set` method requires only a shared reference.\nBecause of the single assignment restriction `get` can return an `\u0026T` instead of `Ref\u003cT\u003e`\nor `MutexGuard\u003cT\u003e`.\n\n`once_cell` also has a `Lazy\u003cT\u003e` type, build on top of `OnceCell` which provides the same API as\nthe `lazy_static!` macro, but without using any macros:\n\n```rust\nuse std::{sync::Mutex, collections::HashMap};\nuse once_cell::sync::Lazy;\n\nstatic GLOBAL_DATA: Lazy\u003cMutex\u003cHashMap\u003ci32, String\u003e\u003e\u003e = Lazy::new(|| {\n    let mut m = HashMap::new();\n    m.insert(13, \"Spica\".to_string());\n    m.insert(74, \"Hoyten\".to_string());\n    Mutex::new(m)\n});\n\nfn main() {\n    println!(\"{:?}\", GLOBAL_DATA.lock().unwrap());\n}\n```\n\nMore patterns and use-cases are in the [docs](https://docs.rs/once_cell/)!\n\n# Related crates\n\n* [double-checked-cell](https://github.com/niklasf/double-checked-cell)\n* [lazy-init](https://crates.io/crates/lazy-init)\n* [lazycell](https://crates.io/crates/lazycell)\n* [mitochondria](https://crates.io/crates/mitochondria)\n* [lazy_static](https://crates.io/crates/lazy_static)\n* [async_once_cell](https://crates.io/crates/async_once_cell)\n* [generic_once_cell](https://crates.io/crates/generic_once_cell) (bring your own mutex)\n\nParts of `once_cell` API are included into `std` [as of Rust 1.70.0](https://github.com/rust-lang/rust/pull/105587).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatklad%2Fonce_cell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatklad%2Fonce_cell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatklad%2Fonce_cell/lists"}