【发布时间】:2019-03-31 10:07:02
【问题描述】:
我有一个结构,其中包含一个类似结构的 vec:
struct ProcessNode {
...
children: Vec<Rc<ProcessNode>>,
}
不幸的是,当我尝试将某些内容附加到 vec 时,我遇到了一个问题:
let mut parent_node: &mut Rc<ProcessNode> = ...
let mut parent_children: &mut Vec<Rc<ProcessNode>> = &mut parent_node.children;
现在parent_node 在编译期间检出,但parent_children 不能以这种方式引用。为什么?以及如何附加到结构中的 vec 字段?
【问题讨论】:
-
编译器在错误信息中告诉了你原因,建议阅读。如果您不理解错误消息,请提供完整示例以重现错误,并在问题中包含错误消息。
-
请提供minimal reproducible example。 tag description 中有更多 Rust 特定的信息。
标签: rust borrow-checker