为了账号安全,请及时绑定邮箱和手机立即绑定

如何在安全Rust中表达相互递归的数据结构?

如何在安全Rust中表达相互递归的数据结构?

我正在尝试在Rust中实现类似于场景图的数据结构。我想要一个等效于用安全 Rust 表示的C ++代码:struct Node{    Node* parent; // should be mutable, and nullable (no parent)    std::vector<Node*> child;    virtual ~Node()     {         for(auto it = child.begin(); it != child.end(); ++it)        {            delete *it;        }    }    void addNode(Node* newNode)    {        if (newNode->parent)        {            newNode->parent.child.erase(newNode->parent.child.find(newNode));        }        newNode->parent = this;        child.push_back(newNode);    }}我想要的属性:父母对子女拥有所有权可以通过某种引用从外部访问节点碰到一个事件Node可能会改变整个树
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 884 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信