Calling method of Some in a borrowed Option without moving it



I have a struct X contained in a Vec<Rc<RefCell>. X contains an Option where Y implements the method foo(). Now I want to call foo() but I get

"cannot move out of borrowed content"

I call it with


where vector is of the type Vec<Rc<RefCell> and y is Option. I know that unwrap() is the forbidden move but I don’t know how to call foo() otherwise.


You can call the as_mut function to first turn the borrowed option into an option of a borrow:



Great, it works, thank you :slight_smile: After one year of using Rust occasionally the borrowing system is still sometimes a little bit confusing to me.