{"id":16714199,"url":"https://github.com/flier/rust-atomic-traits","last_synced_at":"2025-03-21T20:33:43.044Z","repository":{"id":41025605,"uuid":"190140990","full_name":"flier/rust-atomic-traits","owner":"flier","description":"The traits for generic atomic operations in Rust.","archived":false,"fork":false,"pushed_at":"2024-02-12T12:00:05.000Z","size":63,"stargazers_count":8,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-13T20:49:40.954Z","etag":null,"topics":[],"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/flier.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2019-06-04T06:17:59.000Z","updated_at":"2024-03-26T07:59:31.000Z","dependencies_parsed_at":"2023-12-30T00:23:22.006Z","dependency_job_id":"40cfa50f-0271-408d-a505-b0fdc5483d6f","html_url":"https://github.com/flier/rust-atomic-traits","commit_stats":{"total_commits":25,"total_committers":2,"mean_commits":12.5,"dds":0.07999999999999996,"last_synced_commit":"e743ef79bc39757f26a99e883563c10939fb39f6"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flier%2Frust-atomic-traits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flier%2Frust-atomic-traits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flier%2Frust-atomic-traits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flier%2Frust-atomic-traits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flier","download_url":"https://codeload.github.com/flier/rust-atomic-traits/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221818913,"owners_count":16885851,"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-10-12T20:49:50.892Z","updated_at":"2024-10-28T10:49:58.323Z","avatar_url":"https://github.com/flier.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# atomic-traits [![crate](https://img.shields.io/crates/v/atomic-traits.svg)](https://crates.io/crates/atomic-traits) [![documentation](https://docs.rs/atomic-traits/badge.svg)](https://docs.rs/atomic-traits/) [![Continuous integration](https://github.com/flier/rust-atomic-traits/actions/workflows/ci.yaml/badge.svg)](https://github.com/flier/rust-atomic-traits/actions/workflows/ci.yaml) [![MSRV](https://img.shields.io/badge/MSRV-1.34.0-green)](https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html)\n\nThe traits for generic atomic operations in Rust.\n\n## Compatibility\n\nThe crate is tested for stable and nightly compiler.\n\nCurrent MSRV is `1.34.0`.\n\n## Usage\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\natomic-traits = \"0.4\"\n```\n\nand this to your crate root:\n\n```rust\nextern crate atomic_traits;\n```\n\n## Example\n\n```rust\nextern crate num_traits;\nextern crate atomic_traits;\n\nuse std::sync::atomic::{AtomicUsize, Ordering};\n\nuse num_traits::One;\nuse atomic_traits::{Atomic, NumOps, fetch};\n\n#[derive(Debug, Default)]\npub struct RefCnt\u003cT\u003e(T);\n\nimpl\u003cT\u003e RefCnt\u003cT\u003e\nwhere\n    T: Atomic + NumOps + Default,\n    \u003cT as Atomic\u003e::Type: One\n{\n    pub fn inc(\u0026self) -\u003e \u003cT as Atomic\u003e::Type {\n        self.0.fetch_add(\u003cT as Atomic\u003e::Type::one(), Ordering::Acquire)\n    }\n\n    pub fn dec(\u0026self) -\u003e \u003cT as Atomic\u003e::Type {\n        self.0.fetch_sub(\u003cT as Atomic\u003e::Type::one(), Ordering::Release)\n    }\n\n    pub fn val(\u0026self) -\u003e \u003cT as Atomic\u003e::Type {\n        self.0.load(Ordering::SeqCst)\n    }\n}\n\nlet refcnt = RefCnt::\u003cAtomicUsize\u003e::default();\n\nassert_eq!(refcnt.inc(), 0);\nassert_eq!(refcnt.dec(), 1);\nassert_eq!(refcnt.val(), 0);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflier%2Frust-atomic-traits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflier%2Frust-atomic-traits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflier%2Frust-atomic-traits/lists"}