I'm writing a test OOP project to increase my knowledges. I want to add an object in the object list.
But after I added an object into vector, I also want to change it's values. When I add a "&", I see this:
Just remove the &.
Please don't try and force OOP onto Rust, it will end badly (I have tried it before, and I was frustrated with Rust until I stopped thinking in terms of OOP).
Why can't you move that line before you put it inside the window?
Are you trying to share the circle between the window and the main function?
Can you make Circle implement Copy?
Are you going to use Circle after you put it in window? Can you refactor to prevent that? If not, you can wrap your Circle in Rc<RefCell<Circle>> and pass that. The Rc<_> allows you to share it by cloning the Rc (which just increments a reference counter), and the RefCell<_> allows you to regain mutability that waws lost when you went to Rc<_> because sharing is immutable by default in Rust. Although I would encourage you to really think about if you really need to share Circle. In most cases you don't actually need to, and can refactor it so that you don't share Circle.