{"id":16162399,"url":"https://github.com/sunsided/default-option-arr","last_synced_at":"2026-03-05T17:43:09.183Z","repository":{"id":170132484,"uuid":"646246006","full_name":"sunsided/default-option-arr","owner":"sunsided","description":"Macros for simple default initialization of arrays of option types","archived":false,"fork":false,"pushed_at":"2025-06-24T09:03:55.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-28T08:31:17.469Z","etag":null,"topics":["rust","rust-macros"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/default-option-arr","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"eupl-1.2","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sunsided.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2023-05-27T18:54:46.000Z","updated_at":"2025-06-24T09:03:59.000Z","dependencies_parsed_at":"2024-07-09T11:46:59.301Z","dependency_job_id":null,"html_url":"https://github.com/sunsided/default-option-arr","commit_stats":null,"previous_names":["sunsided/default-option-arr"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/sunsided/default-option-arr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fdefault-option-arr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fdefault-option-arr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fdefault-option-arr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fdefault-option-arr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunsided","download_url":"https://codeload.github.com/sunsided/default-option-arr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fdefault-option-arr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30139505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T16:58:46.102Z","status":"ssl_error","status_checked_at":"2026-03-05T16:58:45.706Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["rust","rust-macros"],"created_at":"2024-10-10T02:29:59.879Z","updated_at":"2026-03-05T17:43:09.156Z","avatar_url":"https://github.com/sunsided.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Default Array-of-Option\\\u003cT\\\u003e Macros\n\nMacros to make your life easier when dealing with default-initialized\narrays of `Option\u003cT\u003e` or `Cell\u003cOption\u003cT\u003e\u003e` for non-`Copy` types of `T` to `[None, ..]`.\n\n### You may need it if ...\n\n- You need an array of `[Option\u003cT\u003e; N]` initialized to `[None; N]`, or\n- You need an array of `[Cell\u003cOption\u003cT\u003e\u003e; N]` initialized to `[Cell::new(None); N]`, or\n- You need an array of `[RefCell\u003cOption\u003cT\u003e\u003e; N]` initialized to `[RefCell::new(None); N]`.\n\n### You will not need it if ...\n\n- Your types already implement `Copy` or `Clone` and you don't need cells.\n- You require `#![forbid(unsafe_code)]`.\n\n## Examples\n\n```rust\nuse core::cell::Cell;\nuse arraysetcell::ArraySetCell;\n\n// This type does not implement Copy.\nstruct Complicated;\n\nfn it_works() {\n    // This doesn't compile:\n    let arr: [Option\u003cComplicated\u003e; 10] = [None; 10];\n\n    // This does:\n    let arr = none_arr![Complicated; 10];\n\n    // [None, None, None, ...]\n    assert_eq!(arr.len(), 10);\n    for item in arr.into_iter() {\n        assert!(item.is_none());\n    }\n\n    // The created type is an array.\n    let arr: [Option\u003cComplicated\u003e; 10] = arr;\n    assert_eq!(arr.len(), 10);\n}\n```\n\nLikewise, arrays of `Cell\u003cOption\u003cT\u003e\u003e` can be created.\n\n```rust\nfn cell_works() {\n    let arr: [Cell\u003cOption\u003cComplicated\u003e\u003e; 10] = none_cell_arr![Complicated; 10];\n    let arr: [RefCell\u003cOption\u003cComplicated\u003e\u003e; 10] = none_refcell_arr![Complicated; 10];\n}\n```\n\n## I cannot have unsafe code\n\nIf you cannot have `unsafe` code in your project, something like the following can be used:\n\n```rust\nfn not_fun() {\n    let arr: [Option\u003cComplicated\u003e; 10] = (0..10)\n        .into_iter()\n        .map(|_| None)\n        .collect::\u003cVec\u003c_\u003e\u003e()\n        .try_into()\n        .map_err(|_| \"try_into failed\") // Debug required otherwise\n        .expect(\"initialization failed\");\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Fdefault-option-arr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunsided%2Fdefault-option-arr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Fdefault-option-arr/lists"}