{"id":13438516,"url":"https://github.com/orium/archery","last_synced_at":"2025-10-04T02:27:40.902Z","repository":{"id":34219349,"uuid":"171759424","full_name":"orium/archery","owner":"orium","description":"Abstract over the atomicity of reference-counting pointers in rust","archived":false,"fork":false,"pushed_at":"2025-04-04T10:50:40.000Z","size":164,"stargazers_count":151,"open_issues_count":5,"forks_count":14,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-14T15:01:16.952Z","etag":null,"topics":["arc","concurrency","memory-management","rc","reference-counting","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orium.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2019-02-20T22:29:53.000Z","updated_at":"2025-04-04T10:50:44.000Z","dependencies_parsed_at":"2024-02-12T23:30:25.888Z","dependency_job_id":"1d3604d0-cef3-43eb-966e-9a1edc2d862c","html_url":"https://github.com/orium/archery","commit_stats":{"total_commits":98,"total_committers":4,"mean_commits":24.5,"dds":"0.12244897959183676","last_synced_commit":"cd3e04e1aa6da9fcefbfe27e539cba854cfc2ffd"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orium%2Farchery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orium%2Farchery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orium%2Farchery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orium%2Farchery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orium","download_url":"https://codeload.github.com/orium/archery/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254310513,"owners_count":22049468,"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":["arc","concurrency","memory-management","rc","reference-counting","rust"],"created_at":"2024-07-31T03:01:06.173Z","updated_at":"2025-10-04T02:27:35.856Z","avatar_url":"https://github.com/orium.png","language":"Rust","readme":"[![Build Status](https://github.com/orium/archery/workflows/CI/badge.svg)](https://github.com/orium/archery/actions?query=workflow%3ACI)\n[![Code Coverage](https://codecov.io/gh/orium/archery/branch/main/graph/badge.svg)](https://codecov.io/gh/orium/archery)\n[![Dependency status](https://deps.rs/repo/github/orium/archery/status.svg)](https://deps.rs/repo/github/orium/archery)\n[![crates.io](https://img.shields.io/crates/v/archery.svg)](https://crates.io/crates/archery)\n[![Downloads](https://img.shields.io/crates/d/archery.svg)](https://crates.io/crates/archery)\n[![Github stars](https://img.shields.io/github/stars/orium/archery.svg?logo=github)](https://github.com/orium/archery/stargazers)\n[![Documentation](https://docs.rs/archery/badge.svg)](https://docs.rs/archery/)\n[![License](https://img.shields.io/crates/l/archery.svg)](./LICENSE.md)\n\u003cimg src=\"https://raw.githubusercontent.com/orium/archery/main/images/archery.svg?sanitize=true\" width=\"240\" align=\"right\"\u003e\n\n# `archery`\n\n\u003c!-- cargo-rdme start --\u003e\n\n`archery` is a rust library that offers a way to abstraction over\n[`Rc`](https://doc.rust-lang.org/stable/alloc/rc/struct.Rc.html) and\n[`Arc`](https://doc.rust-lang.org/stable/alloc/sync/struct.Arc.html) smart pointers.\nThis allows you to create data structures where the pointer type is parameterizable, so you can\n[avoid the overhead of `Arc`](https://doc.rust-lang.org/stable/alloc/sync/struct.Arc.html#thread-safety)\nwhen you don’t need to share data across threads.\n\nIn languages that supports\n[higher-kinded polymorphism](https://en.wikipedia.org/wiki/Type_class#Higher-kinded_polymorphism)\nthis would be simple to achieve without any library, but\n[rust does not support that yet](https://github.com/rust-lang/rfcs/issues/324).\nTo mimic higher-kinded polymorphism `archery` implements the approach suggested by\nJoshua Liebow-Feeser in\n“[Rust has higher kinded types already… sort of](https://joshlf.com/post/2018/10/18/rust-higher-kinded-types-already/)”.\nWhile [other approaches](#alternative-approaches) exist, they seem to always offer poor\nergonomics for the user.\n\n## Setup\n\nTo use `archery` add the following to your `Cargo.toml`:\n\n```toml\n[dependencies]\narchery = \"\u003cversion\u003e\"\n```\n\n## Using `archery`\n\n`archery` defines a [`SharedPointer`](https://docs.rs/archery/latest/archery/shared_pointer/struct.SharedPointer.html)\nthat receives the [kind of pointer](https://docs.rs/archery/latest/archery/shared_pointer/kind/trait.SharedPointerKind.html)\nas a type parameter.  This gives you a convenient and ergonomic way to abstract the pointer\ntype away.\n\n### Example\n\nDeclare a data structure with the pointer kind as a type parameter bounded by\n[`SharedPointerKind`](https://docs.rs/archery/latest/archery/shared_pointer/kind/trait.SharedPointerKind.html):\n\n```rust\nuse archery::*;\n\nstruct KeyValuePair\u003cK, V, P: SharedPointerKind\u003e {\n    pub key: SharedPointer\u003cK, P\u003e,\n    pub value: SharedPointer\u003cV, P\u003e,\n}\n\nimpl\u003cK, V, P: SharedPointerKind\u003e KeyValuePair\u003cK, V, P\u003e {\n    fn new(key: K, value: V) -\u003e KeyValuePair\u003cK, V, P\u003e {\n        KeyValuePair {\n            key: SharedPointer::new(key),\n            value: SharedPointer::new(value),\n        }\n    }\n}\n```\n\nTo use it just plug-in the kind of pointer you want:\n\n```rust\nlet pair: KeyValuePair\u003c_, _, RcK\u003e =\n    KeyValuePair::new(\"António Variações\", 1944);\n\nassert_eq!(*pair.value, 1944);\n```\n\n### `triomphe::Arc`\n\nYou can also use [`triomphe::Arc`](https://docs.rs/triomphe/latest/triomphe/struct.Arc.html)\nas the backing implementation of a [`SharedPointer`](https://docs.rs/archery/latest/archery/shared_pointer/struct.SharedPointer.html).\nThis is generally faster than [`std::sync::Arc`](https://doc.rust-lang.org/stable/alloc/sync/struct.Arc.html).\nRead [`triomphe`’s crate documentation](https://docs.rs/triomphe/latest/triomphe/) to learn more\nabout it.\n\nTo use it you need to enable the `triomphe` feature in `archery`. Use `ArcTK` as the pointer\nkind in [`SharedPointer`](https://docs.rs/archery/latest/archery/shared_pointer/struct.SharedPointer.html).\n\n### Serialization\n\nWe support serialization through [serde](https://crates.io/crates/serde).  To use it\nenable the `serde` feature.  To do so change the archery dependency in your `Cargo.toml` to\n\n```toml\n[dependencies]\narchery = { version = \"\u003cversion\u003e\", features = [\"serde\"] }\n```\n## Limitations\n\nCurrently it is not possible to have unsized types inside a\n[`SharedPointer`](https://docs.rs/archery/latest/archery/shared_pointer/struct.SharedPointer.html).  As a workaround you can put the\nunsized type inside a [`Box`](https://doc.rust-lang.org/stable/alloc/boxed/struct.Box.html).\n\n## Alternative approaches\n\nAn alternative to the approach taken by `archery` is to use traits with associated types to encode\ntype-level functions.  This has been suggested\n[multiple](https://github.com/orium/rpds/issues/7#issuecomment-362635901)\n[times](https://joshlf.com/post/2018/10/18/rust-higher-kinded-types-already/#comment-4160863400),\nbut offers ugly ergonomics (see\n[here](https://github.com/Marwes/rpds/blob/e482d5abbaa6c876d7c624e497affe7299bbeece/src/sequence/vector/mod.rs#L153)\nand [here](https://github.com/Marwes/rpds/blob/e482d5abbaa6c876d7c624e497affe7299bbeece/src/sequence/vector/mod.rs#L249)).\n\n\u003c!-- cargo-rdme end --\u003e\n","funding_links":[],"categories":["Libraries","库 Libraries","Rust","库"],"sub_categories":["Concurrency","并发性 Concurrency","并发","并发 Concurrency"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forium%2Farchery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forium%2Farchery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forium%2Farchery/lists"}