百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

archery

> 编程语言
开源

Rust 中引用计数指针的原子性摘要

178 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Rust 中引用计数指针的原子性摘要

archery

archery is a rust library that offers a way to abstraction over Rc and Arc smart pointers. This allows you to create data structures where the pointer type is parameterizable, so you can avoid the overhead of Arc when you don’t need to share data across threads.

In languages that supports higher-kinded polymorphism this would be simple to achieve without any library, but rust does not support that yet. To mimic higher-kinded polymorphism archery implements the approach suggested by Joshua Liebow-Feeser in “Rust has higher kinded types already… sort of”. While other approaches exist, they seem to always offer poor ergonomics for the user.

Setup

To use archery add the following to your Cargo.toml:

toml
[dependencies]
archery = ""

Using archery

archery defines a SharedPointer that receives the kind of pointer as a type parameter. This gives you a convenient and ergonomic way to abstract the pointer type away.

Example

Declare a data structure with the pointer kind as a type parameter bounded by SharedPointerKind:

rust
use archery::*;

struct KeyValuePair {
    pub key: SharedPointer,
    pub value: SharedPointer,
}

impl KeyValuePair {
    fn new(key: K, value: V) -> KeyValuePair {
        KeyValuePair {
            key: SharedPointer::new(key),
            value: SharedPointer::new(value),
        }
    }
}

To use it just plug-in the kind of pointer you want:

rust
let pair: KeyValuePair =
    KeyValuePair::new("António Variações", 1944);

assert_eq!(*pair.value, 1944);

triomphe::Arc

You can also use triomphe::Arc as the backing implementation of a SharedPointer. This is generally faster than std::sync::Arc. Read triomphe’s crate documentation to learn more about it.

To use it you need to enable the triomphe feature in archery. Use ArcTK as the pointer kind in SharedPointer.

Serialization

We support serialization through serde. To use it enable the serde feature. To do so change the archery dependency in your Cargo.toml to

toml
[dependencies]
archery = { version = "", features = ["serde"] }

Limitations

Currently it is not possible to have unsized types inside a SharedPointer. As a workaround you can put the unsized type inside a Box.

Alternative approaches

An alternative to the approach taken by archery is to use traits with associated types to encode type-level functions. This has been suggested multiple times, but offers ugly ergonomics (see here and here).

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustarcconcurrencymemory-managementrc

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言