am getting error "move occurs because self.connection has type std::option::Option<std::vec::Vec<std::boxed::Box<eulerian::Node>>>, which does not implement the Copy trait
| help: consider borrowing the Option's content: self.connection.as_ref()"
at
self.connection.unwrap().push(heap_node);
But when I try to use self.connection.as_ref().unwrap().push(heap_node);
I get follwing error
Practically you don't need type signature like Vec<Box<T>>. Actually, in Rust the Box<T> is not needed usually. The only practical case for many people that the Box<T> actually solve the problem is when they want to define recursive types like struct Node<T>(T, Option<Box<Node<T>>>).
They implement special behaviour to referencing, as memory management is done by ownership. More examples of smart pointers you might be interested are Rc (to provide multiple references to the same object) and Refcell (to provide inner mutability). Composition of smart pointers is possible and eventually necessary, but not all of them are.
Collections (std::collections - Rust) like Vec which you might be interested in and are useful are HashSet, HashMap, LinkedList.
I read about smart pointers.I will look into collections implementations.But can you tell me what is proper implementation of my small snippet code which I posted above.
@ninja0x0 Well, I'm in no position greater than anybody here to say what is proper or not. Much probably, someone can answer you with more property if I miss something.
What I understand from the snippet you've provided is that you want a Node to reference as many nodes the user needs. And it is implicit that a Node may be referenced according to the user's will as well.
The std::rc::Rc is required, which will allow us to have any node to be pointed by as many nodes as we want.
Also, for a Node to point to more than one node, we need some Collection. To avoid unnecessary complications, we may use the most common and standard Vec.