I want to get an element from a vector if the condition for this element is true.
fn draw() -> Option<String> { let mut v: Vec<String> = vec!["foo".to_string()]; let t: Option<String>; let o = v.last();
playground
This results in an error:
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable --> src/main.rs:12:21 | 4 | let o = v.last(); | - immutable borrow occurs here ... 12 | t = v.pop(); | ^ mutable borrow occurs here ... 20 | } | - immutable borrow ends here
What kind I understand, however, I see no way to end the loan (without using clone() ).
source share