{"id":24752627,"url":"https://github.com/adri326/veccell","last_synced_at":"2025-10-10T23:30:35.598Z","repository":{"id":41090176,"uuid":"508258357","full_name":"adri326/veccell","owner":"adri326","description":"A variant of Vec with interior mutability","archived":false,"fork":false,"pushed_at":"2023-06-02T12:09:15.000Z","size":56,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-21T15:07:35.270Z","etag":null,"topics":["interior-mutability","refcell","rust","vec"],"latest_commit_sha":null,"homepage":"https://docs.rs/veccell","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/adri326.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-apache.txt","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":"2022-06-28T10:46:17.000Z","updated_at":"2024-01-28T01:30:06.000Z","dependencies_parsed_at":"2025-01-28T11:01:37.291Z","dependency_job_id":null,"html_url":"https://github.com/adri326/veccell","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/adri326/veccell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adri326%2Fveccell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adri326%2Fveccell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adri326%2Fveccell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adri326%2Fveccell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adri326","download_url":"https://codeload.github.com/adri326/veccell/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adri326%2Fveccell/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005573,"owners_count":26083919,"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-10-10T02:00:06.843Z","response_time":62,"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":["interior-mutability","refcell","rust","vec"],"created_at":"2025-01-28T10:50:35.920Z","updated_at":"2025-10-10T23:30:35.342Z","avatar_url":"https://github.com/adri326.png","language":"Rust","readme":"# VecCell\n\nA variant of `Vec`, with interior mutability, where one element may be borrowed mutably and several other elements may be borrowed immutably at the same time.\n\nYou would use this crate if:\n\n- You need a `Vec` with interior mutability\n- You only want mutable access to one element at a time\n- You want immutable access to all other elements while an element is borrowed mutably\n- You need a constant memory cost for the aliasing checks\n\nYou would need something else if:\n\n- You don't need interior mutability *(you may use `Vec\u003cT\u003e` instead)*\n- While an element is borrowed mutably, you don't need to access the others *(you may use `RefCell\u003cVec\u003cT\u003e\u003e` instead)*\n- You want mutable access to multiple elements at a time *(you may use `Vec\u003cRefCell\u003cT\u003e\u003e` instead)*\n- You need to share the array across multiple threads *(you may use `Vec\u003cMutex\u003cT\u003e\u003e` or `Arc\u003cVec\u003cMutex\u003cT\u003e\u003e\u003e` instead)*\n\n## Installation\n\nRun `cargo add veccell` or add the following in `Cargo.toml`:\n\n```toml\n[dependencies]\nveccell = \"0.4\"\n```\n\n## Examples\n\n`VecCell` allows an element to be borrowed mutably, and other elements to be accessed immutably:\n\n```rust\nuse veccell::VecCell;\n\nlet mut arr: VecCell\u003cusize\u003e = VecCell::new();\n\narr.push(32);\narr.push(48);\narr.push(2);\n\nlet mut third = arr.borrow_mut(2).unwrap(); // Borrow the third element mutably\nlet first = arr.borrow(0).unwrap(); // Borrow the first element immutably\n\n*third *= *first; // Multiply the third element by the first element\n\nprintln!(\"{}\", third); // Prints 64\nstd::mem::drop(third); // Drop the mutable borrow\n\nprintln!(\"{}\", arr.borrow(2).unwrap()); // Also prints 64\n```\n\nHowever, to prevent aliasing, while an element is borrowed mutably, it cannot be borrowed immutably:\n\n```rust\nuse veccell::VecCell;\n\nlet mut arr: VecCell\u003cusize\u003e = VecCell::new();\n\narr.push(32);\narr.push(48);\narr.push(8);\n\nlet mut third = arr.borrow_mut(2).unwrap(); // Borrow the third element mutably\n\n// Here, arr.borrow(2) returns None,\n// because the third element is already borrowed mutably.\nlet third2 = arr.borrow(2);\n\nassert!(third2.is_none());\n\nstd::mem::drop(third);\n```\n\n`VecCell` only stores two additional pieces of information:\n\n- which element is currently borrowed mutably (accessible through `mut_borrow`)\n- how many elements are borrowed immutably (accessible through `borrows`)\n\nThis has the advantage of putting all of its elements next to each other in memory, if their padding allows it, but has the disadvantage of having more restrictive rules than you'd expect:\n\nTo borrow an element mutably, no element must be borrowed mutably *or immutably*:\n\n```rust\nuse veccell::VecCell;\n\nlet mut arr: VecCell\u003cusize\u003e = VecCell::new();\n\narr.push(32);\narr.push(48);\narr.push(8);\n\nlet second = arr.borrow(1).unwrap();\n\nlet third = arr.borrow_mut(2);\n\n// VecCell has no way of telling that the existing immutable borrow (`second`)\n// isn't borrowing the third element.\nassert!(third.is_none());\n\nstd::mem::drop(third);\n\nlet first = arr.borrow_mut(0);\n\n// VecCell can only allow one mutable borrow at a time\nassert!(arr.borrow_mut(1).is_none());\n```\n\n## serde\n\n`serde` is supported. To use it, enable the `serde` feature:\n\n```toml\n[dependencies]\nveccell = { version = \"0.4\", features = [\"serde\"] }\n```\n\n## License\n\nThis project is dual-licensed under the MIT license and the Apache v2.0 license.\nYou may choose either of those when using this library.\n\nAny contribution to this repository must be made available under both licenses.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadri326%2Fveccell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadri326%2Fveccell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadri326%2Fveccell/lists"}