{"id":22253669,"url":"https://github.com/nitrokey/ref-swap","last_synced_at":"2025-03-25T12:25:47.920Z","repository":{"id":171024805,"uuid":"644269744","full_name":"Nitrokey/ref-swap","owner":"Nitrokey","description":"Safe wrapper around AtomicPtr","archived":false,"fork":false,"pushed_at":"2024-04-12T10:06:37.000Z","size":40,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-19T06:48:55.463Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nitrokey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSES/Apache-2.0.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":"2023-05-23T07:11:10.000Z","updated_at":"2023-05-23T07:11:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"50284a32-109b-4e98-b0ce-926975d4a715","html_url":"https://github.com/Nitrokey/ref-swap","commit_stats":null,"previous_names":["nitrokey/ref-swap"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nitrokey%2Fref-swap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nitrokey%2Fref-swap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nitrokey%2Fref-swap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nitrokey%2Fref-swap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nitrokey","download_url":"https://codeload.github.com/Nitrokey/ref-swap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245460457,"owners_count":20619072,"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-12-03T07:19:23.244Z","updated_at":"2025-03-25T12:25:47.866Z","avatar_url":"https://github.com/Nitrokey.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\nCopyright (C) 2023 Nitrokey GmbH\nSPDX-License-Identifier: CC0-1.0\n--\u003e\n\nRef-Swap\n========\n\nSafe wrapper around [`AtomicPtr`](https://doc.rust-lang.org/core/sync/atomic/struct.AtomicPtr.html).\nInstead of swapping a pointer, it works with references and lifetimes, allowing a safe API.\nTwo versions are provided:\n- [`RefSwap`](https://docs.rs/ref-swap/latest/ref_swap/struct.RefSwap.html) for swapping references\n- [`OptionRefSwap`](https://docs.rs/ref-swap/latest/ref_swap/struct.OptionRefSwap.html) for swapping `Option\u003c\u0026T\u003e`.\n[`OptionRefSwap`](https://docs.rs/ref-swap/latest/ref_swap/struct.OptionRefSwap.html) encodes `None` as a null pointer and has no additionnal overhead.\n\nWith references\n---------------\n\n```rust\nuse ref_swap::RefSwap;\nuse core::sync::atomic::Ordering;\n\nlet a = 10;\nlet b = 20;\nlet reference = RefSwap::new(\u0026a);\n\n// In another thread\nlet loaded = reference.load(Ordering::Relaxed);\nassert_eq!(loaded, \u0026a);\nassert!(core::ptr::eq(loaded, \u0026a));\n\nreference.store(\u0026b, Ordering::Relaxed);\n\n// In another thread\nlet loaded = reference.load(Ordering::Relaxed);\nassert_eq!(loaded, \u0026b);\nassert!(core::ptr::eq(loaded, \u0026b));\n```\n\nWith optionnal references\n-------------------------\n\n\n```rust\nuse ref_swap::OptionRefSwap;\nuse core::sync::atomic::Ordering;\n\nlet a = 10;\nlet b = 20;\nlet reference = OptionRefSwap::new(None);\n\n// In another thread\nlet loaded = reference.load(Ordering::Relaxed);\nassert_eq!(loaded, None);\n\nreference.store(Some(\u0026b), Ordering::Relaxed);\n\n// In another thread\nlet loaded = reference.load(Ordering::Relaxed);\nassert_eq!(loaded, Some(\u0026b));\nassert!(core::ptr::eq(loaded.unwrap(), \u0026b));\n\nreference.store(Some(\u0026a), Ordering::Relaxed);\n\n// In another thread\nlet loaded = reference.load(Ordering::Relaxed);\nassert_eq!(loaded, Some(\u0026a));\nassert!(core::ptr::eq(loaded.unwrap(), \u0026a));\n```\n\n## License\n\nThis project is licensed under the [GNU Lesser General Public License (LGPL)\nversion 3][LGPL-3.0].  Configuration files and examples are licensed under the\n[CC0 1.0 license][CC0-1.0].  For more information, see the license header in\neach file.  You can find a copy of the license texts in the\n[`LICENSES`](./LICENSES) directory.\n\n[LGPL-3.0]: https://opensource.org/licenses/LGPL-3.0\n[CC0-1.0]: https://creativecommons.org/publicdomain/zero/1.0/\n\nThis project complies with [version 3.0 of the REUSE specification][reuse].\n\n[reuse]: https://reuse.software/practices/3.0/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitrokey%2Fref-swap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnitrokey%2Fref-swap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitrokey%2Fref-swap/lists"}