Box
堆内存分配的智能指针,用于存储固定大小或递归数据结构。
let boxed = Box::new(42);
基础
智能指针
Rc
单线程引用计数智能指针,用于实现多重所有权。
let shared = Rc::new(value);
基础
智能指针
Arc
原子引用计数,用于在线程间安全地共享数据。
let shared = Arc::new(value);
中级
智能指针
ArcSwap
原子性引用交换容器,用于高效共享和更新不可变数据。
let config = ArcSwap::new(Arc::new(data));
高级
同步原语
Cow
写时复制智能指针,延迟数据克隆直到需要修改时。
let cow = Cow::from("hello");
中级
智能指针
SendWrapper
将非 Send 类型包装成 Send 类型,使其可以安全地在线程间传递。
let wrapped = SendWrapper::new(non_send_data);
高级
线程安全