我正在嘗試在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可能會改變整個樹
添加回答
舉報
0/150
提交
取消