I am using Rust to build a simple autograd implementation based on Karpathy's micrograd as inspiration, which was written in Python. I am struggling in building the data structure to manage the children. The following is my initial attempt:
enum Op {
Add,
Sub,
Mul,
Div,
}
struct Value<T: Default> {
data: T,
grad: T,
children: Vec<Rc<RefCell<Value<T>>>>,
op: Option<Op>
}
The problem is that, when building the children type, copying is required. In C, I'd use a raw pointer in this situation. How do I go about doing this in Rust? I've tried using Vec<&mut Value<T>> instead, but this leads to hassle if I want to implement the Add traits.