{"id":22281497,"url":"https://github.com/rustyyato/cell-project","last_synced_at":"2025-07-28T20:30:54.842Z","repository":{"id":40651322,"uuid":"260318555","full_name":"RustyYato/cell-project","owner":"RustyYato","description":null,"archived":false,"fork":false,"pushed_at":"2022-08-08T15:41:15.000Z","size":42,"stargazers_count":8,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-07T18:24:57.704Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RustyYato.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-30T21:05:54.000Z","updated_at":"2023-01-25T06:46:33.000Z","dependencies_parsed_at":"2022-08-10T00:00:38.446Z","dependency_job_id":null,"html_url":"https://github.com/RustyYato/cell-project","commit_stats":null,"previous_names":["krishnasannasi/cell-project"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RustyYato/cell-project","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fcell-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fcell-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fcell-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fcell-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RustyYato","download_url":"https://codeload.github.com/RustyYato/cell-project/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fcell-project/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267580457,"owners_count":24110844,"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","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-12-03T16:18:42.510Z","updated_at":"2025-07-28T20:30:54.513Z","avatar_url":"https://github.com/RustyYato.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cell-project\n\nA safe interface to project through shared references to [`core::cell::Cell`](https://!doc.rust-lang.org/core/cell/struct.Cell.html).\n\nDocumentation:\nhttps://docs.rs/cell-project\n\n```rust\nuse std::cell::Cell;\nuse cell_project::cell_project as cp; // renamed for ergonomics\n\nstruct Point {\n    x: f32,\n    y: f32,\n}\n\nfn get_x_cell(point: \u0026Cell\u003cPoint\u003e) -\u003e \u0026Cell\u003cf32\u003e {\n    cp!(Point, point.x)\n}\n```\n\nThe syntax for the macro is as follows\n\n```rust compile_fail\nlet projection = cp!($TypeOfValue, $value_identifier.$field_identifier);\n```\n\nYou may not pass an expression for `$value_identifier`, if you need to then you should do.\n\n```rust\nlet value = Cell::new(get_point());\nlet projection = cp!(Point, value.y);\n```\n\nIf you need to project through multiple fields then you need to call `cp!` multiple times, once per projection\n\n```rust\nstruct Pair\u003cT\u003e(T, T);\n\n// let some_pair: \u0026Cell\u003cPair\u003cPoint\u003e\u003e;\nlet point = cp!(Pair\u003cPoint\u003e, some_pair.0);\nlet x = cp!(Point, point.x);\n```\n\nnote: for generic types, you can use `_` to infer the generic parameters\n\n```rust\nfn get_x_cell\u003cT\u003e(point: \u0026Cell\u003cPair\u003cT\u003e\u003e) -\u003e \u0026Cell\u003cT\u003e {\n    cp!(Pair\u003c_\u003e, point.0)\n}\n```\n\nSome limitations, you cannot project an enum variant because that is potentially unsound.\n\n```rust\nlet x = Cell::new(Some(0));\n\n// let's imagine a macro like `try_cell_project`, which takes a varaint as well as a type\nlet proj = cell_project::try_cell_project!(Option\u003c_\u003e, Some, x.0).unwrap();\n\nx.set(None); // we can still write to the `Cell` directly\n\n// this will read uninitialized memory (because that's what `None` wrote in)\n// and there is no way to fix this. Enums cannot allow safe projection through\n// a shared mutable reference (like `\u0026Cell\u003c_\u003e`)\nlet _ = proj.get();\n```\nso you cannot project through enums\n\nAnother limitation of stable, you can only project to `Sized` types. For example, if I have a type\n\n```rust\nstruct Unsized(i32, [u8]);\n```\nThen I can only project to the first field, because the second field is `!Sized`\n\n### features\n\n`nightly` - unlocks `cell_project::nightly_cell_project`, which uses the unstable `#![feature(raw_ref_op)]` to\nallow projections to `!Sized` fields.\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustyyato%2Fcell-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustyyato%2Fcell-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustyyato%2Fcell-project/lists"}