Just another one newbie's issue

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:

How to fix that, guys? I’m a newbie, so don’t be angry :smiley:

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).

But what to do with that??59%20PM

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?

Yeah, i’m trying to share o1 with window

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.

Omg, it’s so hard for newbie like me. May be there is any different solution for this problem?

Yeah, Rust has a learning curve. What are you trying to make?

The reason why this is hard is because getting shared mutability right is a hard problem, and Rust doesn’t try and hide that fact.