concurrency - Is there any way to convert a Rc into an Arc?
问题描述
I have a graph node:
pub struct GraphNode<T>
where
T: Clone,
{
pub f: GraphLikeFunc<T>,
pub m: String,
pub children: Vec<Rc<GraphNode<T>>>,
id: Uuid,
}
I'm trying to convert it to:
pub struct ConcurrentGraphNode<T>
where
T: Clone,
{
pub f: GraphLikeFunc<T>,
pub m: String,
pub children: Vec<Arc<ConcurrentGraphNode<T>>>,
id: Uuid,
}
解决方案
You cannot do such a thing without rebuilding the whole graph. The main difference between Rc
and Arc
is that Rc
does not implement Send
and Sync
while Arc
does.
Those guarantees are checked at compile-time, so there is no way to switch directly between those two at runtime: you have to consume your GraphNode
to build a ConcurrentGraphNode
from scratch.
推荐阅读
- visual-studio-code - 从 WSL 环境访问非路径 WSLENV 变量
- cocoapods - Nativescript NativeAPI 找不到 NSURL、NSURLRequest、NSObject
- java - 类型 T 不是有界参数的有效替代品 `
> - xml - 我的 xml 正在将所有文本值设置为“”的节点更改为没有文本值,我该如何阻止它?
- c++ - 给定总和的子数组
- ios - 插入和更新核心数据对象的有效方法 [2020]
- javascript - 无法在 php-ajax-live-search-with-multiple-value 中显示错误消息“未找到结果”
- javascript - 单击时如何使用Javascript绘制一个新的移动球?
- c# - 代码合同机制是否已经死亡并且没有未来?
- php - 如何获取每日记录和总结